We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
###1. 使用!!将变量转成布尔类型
!!
除了false,0,undefined,null,'',NaN返回false,其他的都返回true
false
0
undefined
null
''
NaN
true
+
注意这个规则只适用于数字字符串,其他的会返回NaN,+new Date()会返回时间戳
+new Date()
console.log( + '123') //123 console.log( + '0Abc') //NaN console.log( + new Date()) //时间戳
&&
a && b 表示如果a为真,则执行b;可以用这种方法检查对象是否存在某些属性或者函数
a
b
let user = { name: 'lx' } console.log(user && user.name)
||
ES6的默认参数可能使用||实现的。a = x || 1 表示如果x为false,则a为1
ES6
in
if ('name' in window) { console.log('name is exist') } else { console.log('no') }
NodeList
[].slice.call(element)
Array.from()
The text was updated successfully, but these errors were encountered:
No branches or pull requests
###1. 使用
!!
将变量转成布尔类型除了
false
,0
,undefined
,null
,''
,NaN
返回false
,其他的都返回true
2. 使用
+
将变量转换为数字注意这个规则只适用于数字字符串,其他的会返回
NaN
,+new Date()
会返回时间戳3. 短路条件
&&
4. 使用
||
设置默认值5. 检查对象中是否存在某个属性:
in
6. 把
NodeList
转换成数组[].slice.call(element)
ES6
新增的Array.from()
方法The text was updated successfully, but these errors were encountered: