Why does typeof match typeof ()?

I am learning JavaScript, and I saw in the code the same thing as for typeofand typeof(), for example:

The result is a number in both cases:

console.log(typeof 1); 
console.log(typeof(1));
+4
source share
4 answers

typeofAccording ES5 spec , unary - the same as void, and delete. Wrapping its grouped expression ()is for convenience only (and, in theory, to override the default priority), but has never been considered a function call.

+8
source

Since typeof is an operator (not a function, not an object), and the operator can be used in an expression with a parenthesis:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof

http://www.ecma-international.org/ecma-262/5.1/#sec-11.4.3

+2

typeof - , +, -,%, && .. , "1" , . , , (1) + (2), . , .

+1

The typeof operator is not a function. You can surround the operand with parentheses so that the expression looks like a function call, but the brackets will just act as a grouping operator (the second only for the comma operator in the unknown hierarchy!). In fact, you can decorate the operand with all the punctuation methods without negating the operator.

typeof (2) //"number"
typeof(2) //"number"
typeof ("a", 3) //"number"
typeof (1 + 1) //"number"
0
source

Source: https://habr.com/ru/post/1570214/


All Articles