Author -  Sai gowtham

JavaScript Double (==) equals vs Triple (===) equals

In this tutorial, we are going to learn about the difference between == equals and === equals in JavaScript with the help of examples.

Double Equals (==)

If we use double equals == to compare the two operands of different types the double equals does the coercion before the comparison.

What is Coercion?

Coercion means JavaScript tries to convert the operands to the same type before making the comparison.

Let’s see an example.

First, we are comparing the number 1 with the string "1" using a double equals operator.

1 == "1" // true

In the above example, we will get an output true because string 1 is converted into a number 1.

Triple Equals (===)

The triple equals (===) is used for strict equality checking it means both operands should be same type and value then only it returns true otherwise it returns false.

Example:

1 === "1" // false

In the above example, we are comparing Number 1 with String "1" the value 1 is the same on both sides but the types of both operands are different so that we will get output false.

2 === 2 // true

Here we are comparing Number 2 with Number 2, the value and type of both operands are the same so that we will get output true.

Other Examples

"hello" === "hello" // true
10 == "10" // true
10 === "10" // false
false == 0 // true
false === 0 //false (boolean false === number 0)

Conclusion

The main difference between tripe and double equals is.

  1. Triple equals do the strict comparison in JavaScript it means both value and type should be same

to return true.

  1. Double equals convert the operands to the same type before making the comparison.

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY