Storing and Reusing Data With Variables in JavaScript
JavaScript·3 min read·Mar 13, 2025
In JavaScript, a variable is a named container used to store arbitrary data referred to as a value.
It can be used to store a wide range of information, such as text, numbers, dates, errors, objects, and pretty much anything else you can think of.
Depending on certain conditions, this value may change during the execution of the script and be updated either by the developer through statements, the user through input, or the script itself through logic.
Data types
In JavaScript, variables can store multiple data types regrouped under two categories: primitive values and objects.
Primitive values
Primitive values are fundamental data types like numbers or strings, that represent individual pieces of data.
In JavaScript, there are 7 primitive value types: Boolean, Number, BigInt, String, Undefined, Null, and Symbol.
Boolean
The Boolean type represents a logical value, and holds only one of two values: true or false.
It is used for conditional checks, logical operations, and boolean-based decision making.
For example:
let isOnline = true;let isAvailable = false;Number
The Number type represents numeric data, such as integers or floating-point numbers, both positive and negative.
It is used for arithmetic operations, calculations, and representing quantities or measurements in programs.
For example:
Unlock the Build CLI Apps in JavaScript & Node.js module
Learn how to build, integrate, and safeguard scalable CLI tools, scripts, and apps with JavaScript, Node.js, npm, and Git.
You get immediate access to:
- 45 focused lessons across JavaScript, Node.js, npm, and Git
- 17 real-world projects with commented solutions
- Ongoing updates to this bundle
- Lifetime access to this bundle