Type checking in JavaScript using typeof operator

by Sai gowtham1min read

In javascript, the typeof operator is used to find the data type of the operand.

typeof operator examples

console.log(typeof 4 ) // "number"

console.log(typeof {} )// "object"

console.log(typeof "hello")// "string"

console.log(typeof  [ 1,2,3,4,5])  // "object"

console.log(typeof  function(){} ) // "function"

console.log(typeof undefined ) // 'undefined'

typeof operator returns the datatype in the “string” format.