Data Types in JavaScript – What Values Can Variables Hold?
JavaScript data types refer to the kind of values you can assign to JavaScript variables.
There are two main value types in JavaScript: primitive and non-primitive.
Primitive Data Types
JavaScript has seven primitive values:
- Number
- String
- Boolean
- Undefined
- Null
- Symbol
- BigInt
See the primitive data type page to learn more about JavaScript’s primitive values.
Non-primitive Data
JavaScript has only one primitive data type:
- Objects
See the non-primitive data type page to learn more about JavaScript’s non-primitive value.
Important Stuff to Know about Data Types in JavaScript
JavaScript is a loosely and dynamically typed language. Therefore, you can use the same variable to store different value types.
Here’s an example:
The snippet above first used the teaTime
variable to store a Boolean value.
Then, we changed teaTime
from a Boolean to a Number.
Afterward, the variable got changed to a String data type.
In other words, you can use the teaTime
variable to store any data type because JavaScript is a weakly and dynamically typed language.