Created at

typeof vs instanceof

Use typeof for primitive data types:

'example string' instanceof String // false
typeof 'example string' === 'string' // true

true instanceof Boolean // false
typeof true === 'boolean' // true

99.99 instanceof Number // false
typeof 99.99 === 'number' // true

Use instanceof for custom data types:

const ClassFirst = function () {}
const ClassSecond = function () {}

const instance = new ClassFirst()

typeof instance === 'ClassFirst' // false
typeof instance // 'object'

instance instanceof ClassFirst // true
instance instanceof ClassSecond // false