JS has seven data types: Number, String, Bool, Symbol, BigInt, undefined, NULL, Object

Five basic data types

1.1 digital Number

JS stores Number as a 64-bit floating point Number, which contains 1 symbol, 11 exponent (-1023 to 1024), and 52 significant digits

1.1.1 Number Special value

  1. There are types of 00+ 0,0, pay attention to:
1/0or1/+0= = =Infinity.1/-0= = = -Infinity
Copy the code
  1. Infinity, divided intoInfinity+Infinity-Infinity
  2. Unexpressible numberNaN (Not a Number)But NaN is a number, note:
NaN= = =NaN // fasle
Copy the code

1.1.2 Range and accuracy of Number

MAX_VALUE: 1.79E + 308 that is 1.797×10^308 Number.MIN_VALUE: 5e-324 that is 5×10^-324

Number can represent up to 53 binary digits (52+1=53 binary digits). A 16-bit integer starting with 90 can also be used accurately, but a Number like 9110000000000001 cannot be saved

1.2 String String

1.2.1 Writing method (ES6)

  1. Single quotes'hello'
  2. Double quotation marks"Hello"
  3. The quotation marksHi ` `

What if you want to include single quotes inside single quotes? It’s OK can be written as ‘it\’s OK ‘or ‘it’s OK’ or ‘it’s OK ‘

1.2.2 escape

\’ means’ \\” means “\n means newline \r means carriage return \t means TAB character

1.2.3 Multi-Line String (Enter)

let s = 'It's ok.
Copy the code

1.2.4 Length of the String

Note: ‘\\\\\\’. Length === 3 can be read by subscript string[index] for example:

let str = 'hello'
str[0] // "h"
Copy the code

1.3 Symbol (ES6)

ES6 introduces a new primitive data type, Symbol, that represents unique values. The Symbol value is generated by the Symbol function. This means that object property names can now be of two types: the original string and the new Symbol type. Attribute names that belong to the Symbol type are unique and are guaranteed not to conflict with other attribute names. Such as:

let s = Symbol(a);typeof s // "symbol"
Copy the code

1.4 Boolean Boolean

1.4.1 The following operations yield bool values

  1. No operation! value
  2. Equal to the operation1! = = 2
  3. Comparison operations1 > 2

1.4.2 Five Falsy values

Values that are equivalent to false but not false are undefined, null, NaN, 0, and “.

1.5 BigInt (ES6)

BigInt can represent an arbitrarily large integer.

2 a null, and undefined

Traditionally, null values for non-objects are written as undefined and null values for objects are written as null

Similarities:

  • inifThe default value isfalse
  • In general, both are representativesThere is no

Difference:

  • Null converts to a numeric value0, and undefined is converted to the numeric typeNaN
  • If a variable is declared but not assigned, the default value isundefined
  • Null is a very special object, and one of the most common uses is passed in as a parameter (indicating that the parameter is not an object).
  • Variables or objects that are set to NULL are collected by the memory collector

3 Type Conversion

3.1 turn Number String

grammar

  • String(n)
  • n +”

For example,

let n = 123
String(n) / / "123"
n + ' ' / / "123"
Copy the code

3.2 turn Number String

grammar

  • Number(s)
  • parseFloat(s)
  • s – 0

For example,

let str = "123"
Number(str) / / 123
parseFloat(str) / / 123
str - 0 / / 123
Copy the code

Boolean 3.3 X

grammar

  • Boolean(x)
  • !!!!! x

For example,

Boolean(1) // true
Boolean(0) // false!!!!!1 // true!!!!!0 // false
Copy the code

3.4 turn the String X

grammar

  • String(x)
  • x.toString()

For example,

true.toString() // "true"
Copy the code

Note that 1.toString() is buggy, change to 1.. The toString () or (1). The toString ()