Fe-interview: [js] 第271天 请分析!+[]+!![]+!![]+!![]+!![]+!![]的结果

Created on 11 Jan 2020  ·  2Comments  ·  Source: haizlin/fe-interview

第271天 请分析!+[]+!![]+!![]+!![]+!![]+!![]的结果

我也要出题

js

Most helpful comment

首先出现的运算符包括:一元加、逻辑非、加法(优先级低于前两者);
所以这表达式简化为:!+[] 和 五个 !![] 相加,其中+[]为0,!+[] 则为 true,!![] 也为true,布尔值相加时,先通过Number () 方法转成数字,Number(true)得1,所以最后表达式简化为六个1相加得6。

All 2 comments

首先出现的运算符包括:一元加、逻辑非、加法(优先级低于前两者);
所以这表达式简化为:!+[] 和 五个 !![] 相加,其中+[]为0,!+[] 则为 true,!![] 也为true,布尔值相加时,先通过Number () 方法转成数字,Number(true)得1,所以最后表达式简化为六个1相加得6。

6

Was this page helpful?
0 / 5 - 0 ratings