The instanceof operator returns true if an object is an instance of a specified type.
// Create a Date const time = new Date(); (time instanceof Date); |
// Create an Array const fruits = [“apples”, “bananas”, “oranges”]; (fruits instanceof Array); |
// Create a Map const fruits = new Map([ [“apples”, 500], [“bananas”, 300], [“oranges”, 200] ]); (fruits instanceof Map); |
// Create a Set const fruits = new Set([“apples”, “bananas”, “oranges”]); (fruits instanceof Set); |
The typeof an undefined variable is “undefined.”
typeof car; |
The typeof a variable that has no value is “undefined,” and its value is also undefined.
let car; typeof car; |
Any variable can be cleared by setting its value to undefined
, which will also make its type undefined
.
let car = “Volvo”; car = undefined; |