JavaScript: Equality comparison with ==, === and Object.is

JavaScript: Equality comparison with ==, === and Object.is

#100DaysOfCode is a great engagement to refresh some of the concepts that are basic, but extremely important. Today, I spent time on refreshing my memory on JavaScript's equality operators and methods. Thought, why not to write about it? Traditional...

#100DaysOfCode is a great engagement to refresh some of the concepts that are basic, but extremely important. Today, I spent time on refreshing my memory on JavaScript's equality operators and methods. Thought, why not to write about it?

Traditionally JavaScript provides 2 special operators for equality comparison:

  • == for Abstract Equality Comparison which performs a loose equality between the operands.
  • === for Strict Equality Comparison which performs a strict equality between the operands.

With ES6, we have one more way to perform the Same-value equality using Object.is method. In this article, we will get deeper in understanding the usage, impact and use-cases of all of them.

Abstract Equality Comparison with **`==**`

Abstract equality comparison(aka, loose equality comparison) compares two values for equality, after converting both the values into a common type. In this type of comparison, type coercion is performed by JavaScript.

Type coercion is the automatic or implicit conversion of values from one data type to another (such as strings to numbers).

Let us understand this with an example. Consider two different animals from the type Rodent, i.e, hamsters and guinea pigs. I have no doubts that, the equality comparison with == is going to return true by coercing their type to rodent.

javascript beginner general programming react 100daysofcode

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How native is React Native? | React Native vs Native App Development

Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.

JavaScript Shopping Cart - Javascript Project for Beginners

JavaScript Shopping Cart - javascript shopping cart tutorial for beginnersBuy me a coffee 🍺 https://www.paypal.com/paypalme/ziddahSource Code: https://bit....

Increase Performance of React Applications Via Array JavaScript Methods

Increase Performance of React Applications Via Array JavaScript Methods. We will create a simple event management application in the react to add, update, and delete an event.

React Native Tutorial for Beginners - Build a React Native App [2020]

React Native Tutorial for Beginners - Learn to build an amazing React Native app for iOS & Android. Build a React Native App [2020]

What is React? - React for Beginners #1

What is React? - React for Beginners. When I was learning React, I wanted a tutorial series that jumped straight into code. That's exactly what my aim for this tutorial series is! By the end of this series you should have an excellent understanding of the React environment, with a lot of practical knowledge to pair it with. I'll be focusing less on theory and more on application (other than this video).