js data types include: String, Number, Boolean, Null, Undefined, Symbol, Object, Array, Function.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Javascript scripting language, like other languages, has its own basic data types, expressions and arithmetic operators, and the basic program framework of the program.
#What are the data types in js?
JavaScript data type:
Value type (basic type): String, Number, Boolean , for Null, Undefined, and Symbol.
Reference data types: Object, Array, Function.
Note: Symbol is a new primitive data type introduced in ES6 to represent unique values.
JavaScript has dynamic typing:
JavaScript has dynamic typing. This means that the same variable can be used as different types:
Instance
1 2 3 |
|
JavaScript String
Strings are stored characters (such as " Bill Gates") variable.
The string can be any text in quotes. You can use single or double quotes:
1 2 |
|
You can use quotes within a string as long as they do not match the quotes surrounding the string:
1 2 3 |
|
JavaScript Numbers
JavaScript has only one number type. Numbers can be written with or without a decimal point:
1 2 |
|
Very large or very small numbers can be written using scientific (exponential) notation:
1 2 |
|
JavaScript Boolean
Boolean (logical) can only have two values: true or false.
1 2 |
|
JavaScript Array
The following code creates an array named cars:
1 2 3 4 |
|
or
1 2 |
|
or
1 |
|
1 |
|
Array subscripts are zero-based, so the first item is [0], the second is [1], and so on.
JavaScript Objects
Objects are separated by curly braces. Inside the parentheses, the object's properties are defined in the form of name and value pairs (name : value). Attributes are separated by commas:
1 |
|
The object (person) in the above example has three attributes: firstname, lastname and id.
Spaces and line breaks don't matter. Declarations can span multiple lines:
1 2 3 4 5 |
|
There are two addressing methods for object properties:
1 2 |
|
Undefined and Null
Undefined This Value means the variable does not contain a value.
You can clear a variable by setting its value to null.
1 2 |
|
Declaring variable types
When you declare a new variable, you can use the keyword "new" to declare its type:
1 2 3 4 5 |
|
More For related knowledge, please visit the FAQ column!
The above is the detailed content of What are the js data types?. For more information, please follow other related articles on the PHP Chinese website!