Number
JavaScript does not distinguish between integers and floating-point numbers, and is uniformly represented by number, and the following are valid number types:
// Integer 123 // floating point 0.456 // scientific notation means 1.2345x1000, equivalent to 1234.5 // Negative number // Nan means not a number, which is represented by Nan when the result cannot be evaluated // Infinity is infinitely large, and is represented as infinity when the value exceeds the maximum value that JavaScript can represent.
Number can do arithmetic directly, and the rules and math are consistent:
// 3 // 7.5 // Infinity // NaN // 1 // 1.5
Note that %
the remainder operation is calculated.
String
strings are arbitrary text enclosed in single quotes ' or double quotes, for example, and ‘abc‘
"xyz"
so on. Note that ‘‘
or ""
itself is just a representation, not part of a string, so the string is ‘abc‘
only a
, b
c
this 3 characters.
Boolean value
A Boolean value is exactly the same as a Boolean algebra, with a Boolean value of only true
false
two values, either, either directly, by means of a true
false
true
false
Boolean, or by a Boolean operation.
null and undefined
null
Represents an "empty" value, 0
unlike an empty string, which ‘‘
0
is a numeric value that ‘‘
represents a string of length 0 and null
represents "null".
In other languages, there are also JavaScript-like null
representations, such as Java, which is also used by null
Swift nil
, which is represented by Python None
. However, in JavaScript, there is one and null
similar undefined
, which means "undefined".
The designer of JavaScript wants to null
represent an empty value, whereas the undefined
value is undefined. It turns out that there is no such thing as an egg, and the difference between the two is insignificant. In most cases, we should all use null
. undefined
useful only when judging whether a function parameter is passed or not.
Array
An array is a set of sequentially arranged collections, each of which is called an element. An array of JavaScript can include any data type. For example:
NULL true];
The above array consists of 6 elements. Arrays []
are represented by ,
separate elements.
Another way to create an array is through a Array()
function:
New // array created [1, 2, 3]
However, for the sake of readability of the code, it is strongly recommended to use it directly []
.
The elements of an array can be accessed through an index. Notice that the starting value of the index is 0
:
var NULL true ];arr[// Returns an element with an index of 0, or 1// Returns an element with an index of 5, which is true// Index is out of range, return undefined
Object
A JavaScript object is a set of unordered collections of key-value, for example:
var person = { ' Bob ', Tags: [' js ', ' web ', ' mobile '], ' Beijing ', true, null};
The key of a JavaScript object is a string type, and the value can be any data type. All of the above person
objects define a total of 6 key-value pairs, each of which is also called an object's properties, for example, the property is person
name
‘Bob‘
zipcode
null
.
To get the properties of an object, we use 对象变量.属性名
the following method:
// ' Bob ' // NULL
Excerpt to: Https://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000/ 001434499190108eec0bdf14e704a09935cd112e501e31a000
Data types and variables in JavaScript