InterviewHubPRO
Section Overview
Q196

Question 196 of 521

Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

38%
JavaScript Internals (521 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

What is the purpose of using object is method

Some of the applications of Object's is method are follows,

  1. It is used for comparison of two strings.
  2. It is used for comparison of two numbers.
  3. It is used for comparing the polarity of two numbers.
  4. It is used for comparison of two objects.

Practical Code Example

javascript
// Object.is() determines if two values are the same value (SameValue algorithm):
// Key differences with ===:
console.log(NaN === NaN);            // false
console.log(Object.is(NaN, NaN));    // true (Handles NaN identity correctly!)

console.log(-0 === +0);              // true
console.log(Object.is(-0, +0));      // false (Distinguishes negative zero)