0

Can a object be used without parentheses?

Like so if we are calling a function typeof in js and instead of typing the value in curve brackets, it is typed after the typeof by giving a space in between them. Is typeof("str") == typeof "str"?

11th Oct 2020, 9:09 AM
Aman Kumar
Aman Kumar - avatar
3 Answers
+ 3
Aman Kumar , >It's working. Yes. There is no reason for it to NOT work. It's same as adding parentheses around any other other literal value. Just like +"4" is same as +("4"), typeof "str" is same as typeof("str"), but you really don't need ( ) here. You might need ( ) when you need to get typeof value that an expression evaluates to. If the expression contains operators that have lower precedence than `typeof` use ( ) to group the expression. example. `+` has lower precedence than `typeof` Ā¹ alert(typeof 9+9); //number9 alert(typeof (9+9)); //number [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
11th Oct 2020, 9:45 AM
šŸ‡®šŸ‡³OmkaršŸ•‰
šŸ‡®šŸ‡³OmkaršŸ•‰ - avatar
+ 2
typeof is not a function. it's an operator.
11th Oct 2020, 9:22 AM
šŸ‡®šŸ‡³OmkaršŸ•‰
šŸ‡®šŸ‡³OmkaršŸ•‰ - avatar
0
Can you explain in detail. It's working.
11th Oct 2020, 9:31 AM
Aman Kumar
Aman Kumar - avatar