Horje
What is the use of the Object.is() method in JavaScript ?

The Object.is() method in JavaScript serves the purpose of comparing two values for equality. It returns a boolean value indicating whether the two values are the same.

Syntax:

Object.is(value1, value2)

Parameter:

  • value1: The first value to compare.
  • value2: The second value to compare.

Example: Here,

  • In the first example, Object.is(5, 5) returns true because both values are numerically equal.
  • In the second example, Object.is(5, "5") returns false because the values are of different types (number and string).
  • In the third example, Object.is(NaN, NaN) returns true because both values are NaN.
  • In the fourth example, Object.is(+0, -0) returns false because the two zero values have different signs.

Javascript

console.log(Object.is(5, 5));
console.log(Object.is(5, "5"));
console.log(Object.is(NaN, NaN));
console.log(Object.is(+0, -0));

Output

true
false
true
false



Reffered: https://www.geeksforgeeks.org


JavaScript

Related
What is Event Capturing ? What is Event Capturing ?
How to use if statement in JavaScript ? How to use if statement in JavaScript ?
What is the use of the Array.findIndex() method in JavaScript ? What is the use of the Array.findIndex() method in JavaScript ?
Temporal dead zone in JavaScript Temporal dead zone in JavaScript
What is Window Object in JavaScript ? What is Window Object in JavaScript ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12