请分析!+[]+!![]+!![]+!![]+!![]+!![]的结果

This JavaScript expression relies on some quirky type coercion behaviors. Let's break it down step by step:

  • !+[]: +[] attempts to convert the empty array to a number. This results in 0. The ! (logical NOT) then converts 0 to true.

  • !![]: Similar to above, [] becomes 0, the first ! makes it true, and the second ! makes it false.

Therefore, the expression becomes:

true + false + false + false + false + false

JavaScript converts true to 1 and false to 0 when doing addition. So, the final result is:

1 + 0 + 0 + 0 + 0 + 0

Which equals 1.

posted @ 2024-12-01 09:22  王铁柱6  阅读(16)  评论(0)    收藏  举报