Skip to content

Typeof comparison in Javascript

Why is typeof stringVariable not equal to String;

console.log(typeof 'hello' === String) // returns false

Why does js behave like this?

let arr1 = ['nabeel', 'aron', 123, true]
    // find
let result = arr1.find(function(item, index, array) {
    console.log(typeof item, typeof item === String)
    return (typeof item === String)
console.log("[Find()] String type item exists : ", result)


typeof ‘hello’ will return as ‘string’ (as string type) typeof 5 will return as ‘number’ (as a string)