The difference between the == and === operators in JavaScript

In JavaScript, the == and === operators are used to compare between two operands.

The == operator abstracts, that is, it makes the necessary type conversions before comparing the equality. Syntax of comparison: a == b .

The === operator compares strict equality, meaning that it will not perform type conversions. So if two values ​​are not of the same type, then when compared, the result will return false. Syntax of comparison: a === b .

The difference between the == and === operators in JavaScript Picture 1
The == and === operators in Javascript

Example 1:

 

Output:

 true false 

Example 2:

 

Output:

 true false 

Example 3:

 

Output:

 true false 

In general, the === operator is recommended because it never performs type conversions when making comparisons, so it always produces accurate results.

Readers can learn more about other operators in the article: Operators in JavaScript.

5 ★ | 1 Vote

May be interested

  • Difference Between JavaScript and PythonDifference Between JavaScript and Python
    in this article, tipsmake.com will take you through the main differences between python and javascript.
  • What is Currying in Javascript? How to use Currying in JavaScriptWhat is Currying in Javascript? How to use Currying in JavaScript
    the currying feature in javascript can help you keep your code tidy and give you a new way of seeing how functions work. currying is ideal when you want to break complex logic into smaller, manageable, and self-contained pieces of code.
  • Basic Shell operatorsBasic Shell operators
    there are many operators supported by each shell. our tutorial is based on the default shell (bourne) so we are discussing bourne shell operators in this chapter.
  • Things to know about 'this' in JavaScriptThings to know about 'this' in JavaScript
    are you having trouble understanding the keyword 'this' in javascript ? then please read what you need to know about 'this' in javascript below.
  • Korn Shell OperatorKorn Shell Operator
    this tutorial lists all the operators available in the korn shell. here most of these operators are similar to what we have in the c program language.
  • Udemy's top 5 JavaScript coursesUdemy's top 5 JavaScript courses
    a programming language that runs on any computer in the world. a language does not need any special software to run. a language ranked among the top in the world.
  • Comparison operators in SQL ServerComparison operators in SQL Server
    this article will show the comparison operators that are used to check for equilibrium along with more advanced operators in sql server.
  • Top site with many good JavaScript exercises to practiceTop site with many good JavaScript exercises to practice
    many people, after taking javascript courses and being equipped with some knowledge of the language they pursue, are eager to improve and cultivate these learned skills. so this article will give you a list of the top 3 websites to actually make javascript.
  • What is JavaScript?What is JavaScript?
    javascript is a programming language of html and web. it is lightweight and most commonly used as part of web pages, but their implementation allows client-side scripts to interact with users and create dynamic websites. it is an interpreted programming language with object-oriented capabilities.
  • Learn about ES6 in JavascriptLearn about ES6 in Javascript
    es6 refers to version 6 of the ecma script programming language. ecma script is the standard name for javascript and version 6 is the next version after version 5, released in 2011.