JavaScript Data Types
Table of Contents
JavaScript has 8 data types:
- Undefined (
undefined
) - Null (
null
) - Boolean (
true
/false
) - Number
- BigInt
- String
- Symbol (unique value)
- Object
Object is the only mutable type. Other types are immutable and are called primitive types.
Undefined #
The Undefined type has only one value: undefined
, which means a variable is declared but no value is assigned to it.
|
|
undefined
can be assigned to a variable but one should use null
to represent emptiness.
|
|
Null #
The Null type has only one value: null
, which means empty.
|
|
Boolean #
The Boolean type has two values: true
and false
. The Boolean values are usually used in conditional operations.
|
|
Number #
The Number type represents both integer and floating point numbers.
|
|
The Number type contains some special values: Infinity
, -Infinity
and NaN
(Not a Number).
|
|
JavaScript can only safely store integers in the range of Number.MIN_SAFE_INTEGER
-(253 β 1) to Number.MAX_SAFE_INTEGER
(253 β 1).
|
|
BigInt #
The BigInt type can safely store integers beyond Number.MIN_SAFE_INTEGER
and Number.MAX_SAFE_INTEGER
. To create a BigInt value, append n
to an integer or call the BigInt()
function. Note that when BigInt()
accept a number beyond the safe limits, the number will be rounded.
|
|
String #
The String type represents text.
|
|
Symbol #
The Symbol type represents a unique and immutable value. To create a Symbol value, call Symbol()
function with an optional string as its description.
|
|
Object #
Object is a collection of key-value pairs, similar to a dictionary.
|
|
References #
- Data types - javascript.info
- JavaScript data types and data structures - JavaScript | MDN
- What is the difference between null and undefined in JavaScript? - Stack Overflow#57249968
Comments powered by giscus. If comments are not loaded, giscus may be blocked by your Internet service provider.
Comments powered by Disqus. If comments are not loaded, Disqus may be blocked by your Internet service provider.