Basic data types

1, undefined and xx are not defined

  • Undefined indicates that the variable is not assigned or the function has no return value defined
  • Xx is not defined indicates that XX is not defined
var a;
console.log(a) //undefined

console.log(b) //b is not defined
Copy the code

2. The results of the operation

var c = undefined
console.log(typeof a === undefined) //false
console.log(typeof a === 'undefined') //true
console.log(typeof c) // undefined

console.log(1 / 0) // Infinity

console.log(-1 / 0) // -Infinity

// Computer floating-point number addition is converted to binary operation, the highest accuracy is 17 decimal places, so there is error
console.log(0.1 + 0.2) / / 0.30000000000000004

console.log(10 + 'a') // 10a
console.log(typeof (10 + 'a')) // string
console.log(isNaN(10 + 'a')) //true
console.log(10 - 'a') // NaN
console.log(10 / 'a') // NaN
Copy the code

3. Typeof precedence is higher than addition and lower than unary addition

console.log(typeof '10' * 1) // equivalent to 'string' * 1 NaN
console.log(typeof ('10' * 1)) // number
console.log(typeof +'10') //number

var a = null
console.log(typeof a) // object
console.log([] instanceof Object) //true

// Logic &&(if it is true, then it is false)
// If the first number is true, return the second number
console.log(Boolean(null)) //false
console.log(null && 1) //null
/ / logic or | | (the same is really true, false is false)
// If the first operand is true, return the first operand.
console.log(0 || 0 || 2) / / 2
console.log(1 || 0 || 3) / / 1

// Logical NOT (NOT)
console.log(!1) //false
Copy the code

4. ToSring () and parseInt()

// toString()
var num = 10;
console.log(num.toString()) 10 "/ /"
console.log(num.toString(2)) / / "1010"
console.log(num.toString(8)) / / "12"
console.log(num.toString(16)) //"a"

console.log(typeof String(null)) //string

console.log(Number('+ 12.3')) / / 12.3
console.log(Number('1 + 2.3')) // NaN
console.log(Number('123ac')) // NaN

/ / parseInt () function
// If the converted value is null,undefined, Boolean are converted to NaN
console.log(parseInt('+ 12.3')) // the first digit of 12 is a sign bit, and the rest are numeric bits, which are converted to integers
console.log(parseInt('1 + 2.3')) // the 1 sign bit appears elsewhere, preserving the value before the sign bit
console.log(parseInt('0xa')) / / 10
console.log(parseInt('010')) // 10 does not parse octal
console.log(parseInt('123ac'));
console.log(parseInt('0101'.2))
Copy the code

5. Boolean false

1, undefined (undefined, can’t find value)

2. Null (for null value)

3, false (Boolean false, string “false” Boolean true)

4, 0 (number 0, string “0” Boolean true)

5, NaN (when the result cannot be calculated, it means “non-numerical”; But typeof NaN===”number”)

6, “” (double quotes) or “(single quotes) (empty string, true even with Spaces)

console.log(Boolean(undefined)) // false
console.log(Boolean(null)) // false
console.log(Boolean(false)) // false
console.log(Boolean('false')) // true
console.log(Boolean(0)) // false
console.log(Boolean('0')) // true
console.log(Boolean(NaN)) // false
console.log(Boolean(' ')) // false
Copy the code