Typeof in Javascript

JAVASCRIPT TYPEOF

 

The JavaScript typeof is an operator to recognize the type of its operator and returns the value as a string format

 

The Operand could be any Variable, Object, and Function, its mostly like use to know what type of data type action performing by the operand.

 

Let's explain with the example to deeply understand where, how, and when to use it.

 

Example 1:  How to use typeof in JavaScript.

console.log(typeof 'gomehere');

 

And now what you are expecting in Answer, what its returns, let see in below in the output section.

 

Output

String

So, now the question is? why its returns string? Hope! you know how it happened, because of type of always returns string form of the operand data type.

Let's take more typeof examples to understand.
 

 

Example 2 :

console.log(typeof90 ==='number');
console.log(typeof2.16 ==='number');
console.log(typeof(69) ==='number');   
  

In the above, we have taken three types of pattern and comparing with the number and let's see what happen in the output section.

Output

True
True
True

 

Yeah!! finally, We got true in all patterns because of javascript typeof returns numbers, Thus returns true for all.

 

 

 



About author

Author:- Mukesh Pant

Mukesh Pant

Founder of GOMEHERE and exploring new ideas in multiple areas like technology, programming, travel, sport, utility, and many more for the audience to solve their problems. Also, keep in touch by email mrpant90@gmail.com




Leave a Comments

Scroll to Top