Inne operatory JavaScript
typeof i instanceof to operatory, które służą do określania typu obiektu lub zmiennej w języku JavaScript.

typeof
Oto kilka przykładów użycia:
console.log(typeof "hello"); // string
console.log(typeof 123); // number
console.log(typeof true); // boolean
console.log(typeof {}); // object
console.log(typeof []); // object
console.log(typeof null); // object
console.log(typeof undefined); // undefined
console.log(typeof function() {}); // function
string
number
boolean
object
object
object
undefined
function
instanceof
Oto przykład użycia:
let array = [];
console.log(array instanceof Array); // true
console.log(array instanceof Object); // true
let str = "hello";
console.log(str instanceof String); // false
console.log(str instanceof Object); // false
true
true
false
false

W powyższym przykładzie, operator instanceof sprawdza, czy obiekt array jest instancją klasy Array lub Object. Analogicznie dla ciągu tekstowego str. Wartość false jest zwracana, ponieważ ciągi tekstowe w języku JavaScript są typem prostszym i nie są instancjami klas String lub Object.