Skip to content

JavaScript Object is() | Method

  • by

JavaScript Object is() Method is used to compare two values for strict equality. While it can be used to compare objects, it only returns true if the two objects are the same object in memory.

Object.is(value1, value2)

However, several methods can be used to compare objects, including Object.is(), JSON.stringify(), and lodash.isEqual().

It will only return true if the two objects are the same object in memory (i.e., they have the same reference).

JavaScript Object is() example

Simple example code.

<!DOCTYPE html>
<html>
<body>
    <script>
    const obj1 = { foo: "bar" };
    const obj2 = { foo: "bar" };
    const obj3 = obj1;

    console.log(Object.is(obj1, obj2));
    console.log(Object.is(obj1, obj3));

    </script>
</body>
</html>

Output:

JavaScript Object is() Method

Do comment if you have any doubts or suggestions on this Js object methods topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *