Home  >  Article  >  Web Front-end  >  Seven js data types to share

Seven js data types to share

小云云
小云云Original
2018-03-19 16:45:561552browse


This article mainly shares seven js data types with you, hoping to help everyone.

1, number

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

2, string

The defined string can be enclosed in single quotes or double quotes
string 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` // 含回车符号

3, boolean

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

4, symbol

5, object

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

6, undefined

7, null

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


typeof operator

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

1, number

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

2, string

The defined string can be enclosed in single quotes or double quotes
string 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` // 含回车符号

3, boolean

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

4, symbol

5, object

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

6, undefined

7, null

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


typeof operator

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn