Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

The instanceof Operator

The instanceof operator returns true if an object is an instance of a specified type.

Examples

// 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);

Undefined Variables

The typeof an undefined variable is “undefined.”

Example

typeof car;

The typeof a variable that has no value is “undefined,” and its value is also undefined.

Example

let car;
typeof car;

Any variable can be cleared by setting its value to undefined, which will also make its type undefined.

Example

let car = “Volvo”;
car = undefined;