在javascript中typeof的行为

gop*_*410 2 javascript typeof

有人可以用以下方式解释为什么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)

Den*_*ret 6

typeof不是函数,而是一元运算符,所以

typeof + ""; 
Run Code Online (Sandbox Code Playgroud)

是相同的

typeof (+ "");
Run Code Online (Sandbox Code Playgroud)

并将其+something转换something在一元+运算符上EcmaScript规范预先准备的数字:

一元+运算符将其操作数转换为数字类型.