Featured Article

Difference Between == and === in JavaScript With Example: Strict Equality Explained

Adam Jul 13, 2026

When working with JavaScript, developers often encounter the double equals (==) and triple equals (===) operators, each serving a distinct purpose in value comparison. Understanding the difference between these two is crucial for writing clean, efficient, and accurate code. So, let's dive into the world of == and === in JavaScript, complete with real-life examples.

Difference between JavaScript and HTML
Difference between JavaScript and HTML

Firstly, both == and === are used for comparing two values. However, they differ in the number of types of checks they perform. Let's explore this in detail.

JavaScript Comparison Operators: Master == vs === & More! ⚖️
JavaScript Comparison Operators: Master == vs === & More! ⚖️

Equality (==)

The double equals (==) operator performs two types of checks:

Differences between JavaScript and PHP
Differences between JavaScript and PHP

Value equality: It checks if the values of the two operands are equal or not.

Type coercion: If the types of the two operands are not the same, JavaScript automatically converts them (coerces) to match before making the comparison.

Javascript NULL VS Empty VS Undefined
Javascript NULL VS Empty VS Undefined

Examples of ==

Let's consider a few examples to illustrate this:

  • First, comparing two numbers with the same value: 1 == 1 returns true.
  • Now, let's compare different types but with the same numerical value: 1 == '1' also returns true. This is because JavaScript converts the string '1' to a number before comparing.
JavaScript vs typescript
JavaScript vs typescript

  • However, consider this example: null == undefined. Even though both null and undefined are typically considered "falsy" and often used interchangeably, they are distinct types. Here, JavaScript performs type coercion, converting null and undefined to a number (0) and thus making them equal, hence this returns true.

Strict Equality (===)

The triple equals (===) operator is more strict in its comparison. It performs three types of checks:

two different types of font and numbers on the same page, one is for an email
two different types of font and numbers on the same page, one is for an email

Value equality: It checks if the values of the two operands are equal or not.

Type equality: In addition to value, it also checks if the types of the two operands are the same.

JavaScript Event Handler vs. Event Listener: What’s the Difference? 🎯
JavaScript Event Handler vs. Event Listener: What’s the Difference? 🎯
JavaScript vs TypeScript: Which is Better for Web Projects?
JavaScript vs TypeScript: Which is Better for Web Projects?
The JavaScript Cheat Sheet Every Beginner Wishes They Had
The JavaScript Cheat Sheet Every Beginner Wishes They Had
FrontEnd vs Backend
FrontEnd vs Backend
JavaScript Increment & Decrement Operators: Simplify Your Code 🔄
JavaScript Increment & Decrement Operators: Simplify Your Code 🔄
Permutations & Combinations in Javascript
Permutations & Combinations in Javascript
Java vs. JavaScript
Java vs. JavaScript
JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)
JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)
Comparison operators in JavaScript
Comparison operators in JavaScript
JavaScript vs Node JS
JavaScript vs Node JS
JavaScript vs TypeScript
JavaScript vs TypeScript
What is Triple Equal in JavaScript?
What is Triple Equal in JavaScript?
an image of a flow diagram with two different types of loops and loops on it
an image of a flow diagram with two different types of loops and loops on it
Javascript
Javascript
Difference between var, let, and const in JavaScript? Example Tutorial
Difference between var, let, and const in JavaScript? Example Tutorial
How to Create a Function in JavaScript: Step-by-Step Guide 🚀
How to Create a Function in JavaScript: Step-by-Step Guide 🚀
JavaScript for Loop: The Ultimate Tool for Repeating Tasks 🔄
JavaScript for Loop: The Ultimate Tool for Repeating Tasks 🔄
JavaScript Arrow Functions: Write Shorter & Cleaner Code 🚀
JavaScript Arrow Functions: Write Shorter & Cleaner Code 🚀
Front-End vs. Back-End: What's the Difference? 💻
Front-End vs. Back-End: What's the Difference? 💻
a diagram that shows the different types of web pages and what they are used for
a diagram that shows the different types of web pages and what they are used for

No type coercion: Unlike ==, it does not perform any type coercion. If the types of the two operands are not the same, it returns false.

Examples of ===

Now let's apply these principles with a few examples:

  • Comparing two numbers with the same value and type: 1 === 1 returns true. This is the same as == in this case.
  • However, comparing different types even if the values are the same: 1 === '1' now returns false. Here, JavaScript doesn't perform type coercion and since types are not the same, it returns false.

  • Lastly, comparing null and undefined: null === undefined returns false. Unlike with ==, JavaScript doesn't perform type coercion here, and since null and undefined are different types, it returns false.

In conclusion, the double equals (==) operator is useful when you want to compare values and don't mind JavaScript performing type coercion. However, for more precise and predictable results, always opt for the triple equals (===) operator. It helps prevent unexpected behavior in your code by ensuring both value and type equality.

Now that you understand the difference between == and ===, you're better equipped to write powerful and efficient JavaScript. Happy coding!