Working with typeof operator and ways of calling.

vishalneeraj-24503
Posted by vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 1143
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
typeof(20);
  
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