JavaScript typeof Operator

In JavaScript, the typeof operator returns the data type of its operand in the form of a string. The operand can be any object, function, or variable.
Syntax:
typeof operand
OR
typeof (operand)
Note: Operand is an expression representing the object or primitive whose type is to be returned. The possible types that exist in javascript are:
Below is an example of the typeof operator.
Example: This example checks the typeof of a string, number, and undefined object and returns the value in the console.
javascript
| // "string"console.log(typeof'mukul')// "number"console.log(typeof25)// "undefined"console.log(typeofvariable) | 
Output:
string number undefined
Let’s cover all the types one by one dedicating a single code section for each code.
Example: Typeof Number, in this sample, we used ‘===’ (strict equality comparison operator) which compare value and type both and then return true or false. For example- consider the first console.log(), the js starts compiling from left to right and it first calculates the type of 25 which is ‘number’, and then compares it with ‘number’ and then finally returns true or false accordingly.
javascript
| //Numberconsole.log(typeof25 === 'number');console.log(typeof3.14 === 'number');console.log(typeof(69) === 'number');// log base 10console.log(typeofMath.LN10 === 'number');console.log(typeofInfinity === 'number');// Despite being "Not-A-Number"console.log(typeofNaN === 'number');// Wrapping in Number() functionconsole.log(typeofNumber('100') === 'number'); | 
Output:
true true true true true true true
Fun fact NaN which stands for not-a-number has a type of “number”.
Example: Typeof string
javascript
| // stringconsole.log(typeof''=== 'string');console.log(typeof'bla'=== 'string');// ES6 template literalconsole.log(typeof`template literal` === 'string');console.log(typeof'1'=== 'string');console.log(typeof(typeof1) === 'string');// Wrapping inside String() functionconsole.log(typeofString(1) === 'string'); | 
Output:
true true true true true true
Example: Typeof boolean
javascript
| // Booleanconsole.log(typeoftrue=== 'boolean');console.log(typeoffalse=== 'boolean');// Two calls of the ! (logical NOT) operator// are equivalent to Boolean()console.log(typeof!!(1) === 'boolean'); | 
Output:
true true true
Example: Typeof undefined
javascript
| // Undefinedconsole.log(typeofundefined === 'undefined');// Declared but undefined variableconsole.log(typeofvariable === 'undefined'); | 
Output:
true true
Example: Typeof symbol
javascript
| // Symbolconsole.log(typeofSymbol() === 'symbol');console.log(typeofSymbol('party') === 'symbol');console.log(typeofSymbol.iterator === 'symbol'); | 
Output:
true true true
Example: Typeof object
javascript
| // Objectconsole.log(typeof{ b: 1 } === 'object');console.log(typeof[1, 2, 9] === 'object');console.log(typeofnewDate() === 'object'); | 
Output:
true true true
Example: Typeof function
javascript
| // functionconsole.log(typeoffunction() { } === 'function');//classes too are objectsconsole.log(typeofclass C { } === 'function');console.log(typeofMath.sin === 'function'); | 
Output:
true true true
 
				 
					


