# 类型转换

# 字符串拼接

const b = 100 + '10' // '10010'
const c = true + '10' // 'true10'
const d = true + 1 // 2'

# ==

100 == '100' // true
0 == '' // true
0 == false // true
'' == false // true
null == undefined // true

// 除了 == null 之外,其他都一律用 === ,例如
const obj = { x: 100 }
if (obj.a == null) {}
// 相当于
if (obj.a === null || obj.a === undefined) {}

# if 语句和逻辑运算

if 判断的就是 truly 或者 falsely 变量;逻辑判断也遵循。

  • truly 变量:!!a === true 的变量
  • falsely 变量:!!a === false 的变量

以下是 falsely 变量,除此之外都是 truly 变量

!! 0 === false
!! NaN === false
!! '' === false
!! null === false
!! undefined === false
!! false === false

评 论:

更新: 11/21/2020, 7:00:56 PM