There are six basic data types in JavaScript: boolean (true/false), null (empty value), undefined (undefined value), numerical value, string and symbol (unique identifier). The differences between these data types are their value range, representation, and purpose.
Basic data types in JavaScript
There are six basic data types in JavaScript:
-
Boolean: Boolean value, indicating true (
true
) or false (false
)
-
Null: Null value, indicating a non-existent or unknown value
-
Undefined: Undefined value, indicating that a variable has not been assigned a value
-
Number: Numeric value, including integers, floating point numbers and infinity (
Infinity
)
-
String: String, representing a text consisting of zero or more Unicode characters
-
Symbol: Unique identifier introduced in ES6, used to represent the key name of object properties
The difference between these data types:
-
Boolean value has only two possible values:
true
or false
.
-
Null Represents an explicit null value, indicating that the value does not exist or is unknown.
-
Undefined Indicates that a variable or property has not yet been assigned a value.
-
The value can be an integer (e.g.
123
) or a floating point number (e.g. 3.14
).
-
String is a string of characters enclosed in single quotes (
'
) or double quotes ("
).
-
Symbol is a unique identifier and cannot be used for any purpose other than the key name of an object.
Understanding the basic data types in JavaScript is essential to writing efficient code. Important because it determines how variables store and process data
.
The above is the detailed content of What are the basic data types in js. For more information, please follow other related articles on the PHP Chinese website!