Typeof & Instanceof

Typeof

typeof 123; // number
typeof 'jartto'; // string
typeof !!0’; // boolean
typeof new Function(); // function
typeof name; // undefined


let arr = [1,2,3];
let obj = {name: 'jartto'};
let obj1 = null;
typeof arr; // object
typeof obj; // object
typeof obj1; // object

Instanceof

function Parent(){};
function Child(){};
function Other(){};

Child.prototype = new Parent();
let child = new Child();

child instanceof Child; // true
child instanceof Parent; // true
child instanceof Object; // true
child instanceof Other; // false

Reference

Last updated

Was this helpful?