Numbers include decimal, binary, and octal.
Starting with 0b represents binary.
Starting with 0 represents octal.
0x16.
Note that in js There are no float, int, double and other data types. number contains all numbers
The defined string can be enclosed in single quotes or double quotesstring a='123'
or string a="123"
The length of the empty string is 0
The length of the space string is 1
To represent single quotes' ' '
is a wrong approach
represents two correct ways of using single quotes.
You can enclose it in double quotes "'"
Use the escape character '\' '
Introducing other escape characters by the way
' \n'Line break
'\ t'tab
'\'A slash
Two ways to represent a multi-line string
var s = '12345' + '67890' // 无回车符号
or
var s = `12345 67890` // 含回车符号
The value of boolean
There are only two values: true and false
a && b When a and b are both true, the value is true ; Otherwise, it is false
a || b When a and b are both false, the value is false; otherwise, it is true
object is the above basic types (unordered) combined together
object can have objects inside
var person = {
Name: ‘shuyan’,
‘child’: {
name: ‘Jack’
}, // The last comma is optional
}
The key of object is always a string, there are no other types of keys
object[”] is legal
object['key'] can be written as object.key
Note that object.key and object[key] is different
undefined and null both mean no value. As for why JS has two things that mean "no value" , you can know from the twitter of the father of JS that he was quite confused at that time: https://twitter.com/BrendanEich/status/333008305461006336
(Specification) If a variable is not assigned a value, then the value of the variable is undefiend
(Convention) If you want to represent an object that has not yet been assigned a value, use null. If you want to represent a string/number/boolean/symbol that has not been assigned a value, use the undefined
xxx Type | string | number | boolean | symbol | undefined | null | object | function |
---|---|---|---|---|---|---|---|---|
typeof xxx | 'string' | 'number' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'object' | 'function' |
Note that function is not a type
It is wrong to say that everything in js is an object
array and function are The
numbers belonging to object are decimal, binary, and octal.
Starting with 0b means binary
Starting with 0 means octal
0x16
Note that there are no float, int, double and other data types in js. number contains all numbers
The defined string can be enclosed in single quotes or double quotesstring a='123'
or string a="123"
The length of the empty string is 0
The length of the space string is 1
To represent single quotes' ' '
is a wrong approach
represents two correct ways of using single quotes.
You can enclose it in double quotes "'"
Use the escape character '\' '
Introducing other escape characters by the way
' \n'Line break
'\ t'tab
'\'A slash
Two ways to represent a multi-line string
var s = '12345' + '67890' // 无回车符号
or
var s = `12345 67890` // 含回车符号
The value of boolean
There are only two values: true and false
a && b When a and b are both true, the value is true ; Otherwise, it is false
a || b When a and b are both false, the value is false; otherwise, it is true
object is the above basic types (unordered) combined together
object can have objects inside
var person = {
name: ‘shuyan’,
‘child’: {
name: ‘Jack’
}, // The last comma is optional
}
The key of object is always a string, there are no other types of keys
object[”] is legal
object['key'] can be written as object.key
Note that object.key and object[key] is different
undefined and null both mean no value. As for why JS has two things that mean "no value" , you can know from the twitter of the father of JS that he was quite confused at that time: https://twitter.com/BrendanEich/status/333008305461006336
(Specification) If a variable is not assigned a value, then the value of the variable is undefiend
(Convention) If you want to represent an object that has not been assigned a value, use null. If you want to represent a string/number/boolean/symbol that has not been assigned a value, use the undefined
xxx Type | string | number | boolean | symbol | undefined | null | object | function |
---|---|---|---|---|---|---|---|---|
typeof xxx | 'string' | 'number' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'object' | 'function' |
Note that function is not a type
It is wrong to say that everything in js is an object
array and function belong to object
The above is the detailed content of Seven js data types to share. For more information, please follow other related articles on the PHP Chinese website!