Created
June 19, 2014 03:56
-
-
Save Gerhut/4186b23fceb6971d3658 to your computer and use it in GitHub Desktop.
{}的二义性
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {} + [] // => {}; +[] => 0 | |
| [] + {} // => '' + '[object Object]' => '[object Object]' | |
| {} + [] == [] + {} // => {}; 0 == '[object Object]' => false | |
| ({} + [] == [] + {}) // => '[object Object]' + '' == '' + '[Object Object]' => true | |
| /* | |
| 知识点: | |
| 1. {}放在语句开头的时候,被当做括代码的大括号;不在开头的时候,被当做括对象的大括号。 | |
| 2. 单目运算符 `+ val` 就是把val强转为数字 | |
| 3. +两边只要有非数字,就把两边转为字符串,做字符串连接。 | |
| 4. 空数组转为空字符串,空对象转为'[object Object]' | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
({}) + [] '[object Object]'
{}+{} NaN