A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript-object-is-method/ below:

JavaScript Object is() Method - GeeksforGeeks

JavaScript Object is() Method

Last Updated : 12 Jul, 2024

JavaScript Object.is() method is used to compare if two values are the same value.

Object.is() returns true if the values are the same, and false otherwise. It differs from the strict equality operator === in the handling of NaN and positive/negative zero.

Syntax:
Object.is(value1, value2)
Parameters:

Object.is() Method takes two parameters:

Return Value:

Example: In this example, Object.is() returns true for the first comparison because both values are 5, but false for the second comparison because 5 and '5' are of different types. It returns true for NaN comparison because NaN is considered the same value as itself, and false for 0 and -0 comparison because they are considered different values.

JavaScript
console.log(Object.is(5, 5)); // true
console.log(Object.is(5, '5')); // false
console.log(Object.is(NaN, NaN)); // true
console.log(Object.is(0, -0)); // false

Output
true
false
true
false
Exceptions:

Two values can be the same if they hold one of the following properties: 

We have a complete list of Javascript Object methods, to check those please go through this JavaScript Object Complete Reference article.

Supported Browsers:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4