Open In App

JavaScript in and instanceof operators

Last Updated : 14 Nov, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In JavaScript, the in and instanceof operators are used to check relationships within objects and classes.

  • The in operator checks whether a property exists in an object or an index exists in an array.
  • The instanceof operator checks whether an object is an instance of a specific class or constructor.

Both operators return a Boolean value (true or false) based on the result of the check.

JavaScript in Operator

The in-operator in JavaScript checks if a specified property exists in an object or if an element exists in an array. It returns a Boolean value.

JavaScript
let languages = ["HTML", "CSS", "JavaScript"];

// true (index 1 exists in the array)
console.log(1 in languages);

// false (index 3 doesn't exist in the array)
console.log(3 in languages); 

Output
true
false

Example-Using in with Objects:

JavaScript
const Data = {
    name: "Rahul",
    age: 21,
    city: "Noida"
};

// true ("name" property exists in the object)
console.log("name" in Data);

// false ("gender" property doesn't exist in the object)
console.log("address" in Data);

Output
true
false

JavaScript instanceof Operator

The instanceof operator in JavaScript tests if an object is an instance of a particular class or constructor, returning a Boolean value.

JavaScript
let languages = ["HTML", "CSS", "JavaScript"];

console.log(languages instanceof Array);
console.log(languages instanceof Object);
console.log(languages instanceof String);
console.log(languages instanceof Number);

Output
true
true
false
false

Example–Using in with Objects:

JavaScript
let myString = new String();
let myDate = new Date();

console.log(myString instanceof Object);
console.log(myString instanceof Date);
console.log(myString instanceof String);
console.log(myDate instanceof Date);
console.log(myDate instanceof Object);
console.log(myDate instanceof String);

Output
true
false
true
true
true
false

Explore