JavaScript typeof

JavaScript typeof

JavaScript typeof

 

In JavaScript, the typeof operator is used to determine the type of a value or expression. The typeof operator returns a string that indicates the type of the operand. Here are some examples:

				
					typeof "Hello World" // returns "string"
typeof 42 // returns "number"
typeof true // returns "boolean"
typeof undefined // returns "undefined"
typeof null // returns "object" (this is a bug in JavaScript)
typeof {} // returns "object"
typeof [] // returns "object"
typeof function() {} // returns "function" 

				
			

Note that typeof null returning “object” is considered a bug in JavaScript. Also, typeof does not differentiate between different object types. For example, both an empty object {} and an empty array [] are considered to be of type “object”.

Join To Get Our Newsletter
Spread the love