Working with typeof operator and ways of calling.

Posted by vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 678
The typeof operator is an in-built Javascript operator and is used to identify the type of an object.
It always returns a String value,so we should always compare return value to a string.
typeof is an operand and not a function.
There are 2 ways to call the method.
Consider following Example:-

typeof 10;        
Output :- number
typeof true;
Output :- boolean
typeof undefined;
Output :- undefined
typeof {};
Output :- object

Calling typeof operand with parentheses
Output :- number

As typeof is an operand and not a function,that is the reason,the second method is actually not a function call.
Operation in parentheses are evaluated and then passed to typeof.

Comments or Responses

Login to post response