GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Home
  • ES6
  • Web
  • JS BOM
  • JS DOM
  • Web API
  • React
  • Node.js
  • Express
  • React Native
  • JavaScript Array Methods
  • JavaScript String Methods
  • Regular Expressions
  • ES Next

This view

  • Original page
  • New address

GeezerVison is showing www.javascripttutorial.net — JavaScript Object.is() Method

Home » JavaScript Object Methods » JavaScript Object.is()

Summary: in this tutorial, you will learn about the JavaScript Object.is() method to check if the two values are the same.

The Object.is() behaves like the === operator with two differences:

  • -0 and +0
  • NaN

Negative zero #

The === operator treats -0 and +0 are the same value:

let amount = +0,
    volume = -0;
console.log(volume === amount);

Output:

true

However, the Object.is() treats +0 and -0 as different values. For example:

let amount = +0,
    volume = -0;
console.log(Object.is(amount, volume));

Output

false

NaN #

The === operator considers NaN and NaN are different values. The NaN is the only number that does not equal itself. For example:

let quantity = NaN;
console.log(quantity === quantity);

Output:

false


However, Object.is() treats NaN as the same value:

let quantity = NaN;

console.log(Object.is(quantity, quantity));


Output:

true


See the following sameness comparison table for reference:

JavaScript sameness comparison table

Was this helpful?

Thank you for your feedback!

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.