CodeHelper CodeHelper
首页
JavaScript
PHP
Python
Git速查表 (opens new window)
博客 (opens new window)
首页
JavaScript
PHP
Python
Git速查表 (opens new window)
博客 (opens new window)
  • 开始

    • 使用
  • 函数方法

    • 字符串
    • 数字
    • 数组
    • 日期时间
    • 缓存
    • 深浅拷贝
    • 正则
    • md5
    • 其它
  • 梳理

    • 循环
  • 高级操作

    • 类型转换技巧
      • 转 Number
      • 转 Boolean
    • 防抖与节流
    • Promise实现
目录

类型转换技巧

# 转 Number

let a = '1'

console.log(typeof a) // string
console.log(typeof Number(a)) // number
console.log(typeof +a) // number

# 转 Boolean

let a = '1'

console.log(typeof a) // string
console.log(typeof Boolean(a))  // boolean
console.log(typeof !!a) // boolean

let b = '0'

console.log(!!b) // true
console.log(!!+b) // false, 先转为 Number 再转为 Boolean
上次更新: 2022/08/26, 17:06:25
循环
防抖与节流

← 循环 防抖与节流→

Theme by Vdoing | Copyright © 2022-2023 CodeHelper
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式