Data Types
There are 8 basic data types in JavaScript.
- Seven primitive data types:
numberfor numbers of any kind: integer or floating-point, integers are limited by ±(2^53 - 1).bigintfor integer numbers of arbitrary length.stringfor strings. A string may have zero or more characters, there’s no separate single-character type.booleanfortrue/false.nullfor unknown values – a standalone type that has a single valuenull.undefinedfor unassigned values – a standalone type that has a single valueundefined.symbolfor unique identifiers.
- And one non-primitive data type:
objectfor more complex data structures.
The typeof operator allows us to see which type is stored in a variable.
- Usually used as
typeof x, buttypeof(x)is also possible. - Returns a string with the name of the type, like
"string". - For
nullreturns"object"– this is an error in the language, it’s not actually an object.