有人可以用以下方式解释为什么typeof的行为:
typeof
//Returns: SyntaxError: Unexpected token } (Quite obvious)
"Why am I a " + typeof
//Returns: SyntaxError: Unexpected token }
"Why am I a " + typeof + "";
//Returns: "Why am I a number"
"Why am I a " + typeof + "??";
//Returns: "Why am I a number"
Run Code Online (Sandbox Code Playgroud)
typeof + "";
Run Code Online (Sandbox Code Playgroud)
是相同的
typeof (+ "");
Run Code Online (Sandbox Code Playgroud)
并将其+something转换something为在一元+运算符上以EcmaScript规范预先准备的数字:
一元+运算符将其操作数转换为数字类型.
| 归档时间: |
|
| 查看次数: |
1874 次 |
| 最近记录: |