What is Triple Equal in JavaScript?

What is Triple Equal in JavaScript?

Ferenc Almasi β€’ 2021 January 08 β€’ Read time 1 min read
  • twitter
  • facebook
JavaScript

Javascript uses two different equal signs for equality comparisons. You have abstract and strict equality comparison, or more commonly known as double and triple equal.

The triple equal operator is used to check for strict equality. This means that in order to define two values as equal, both the type and their value must match.

Copied to clipboard!
// Here we check for both value and type, therefore this will return false
'1' === 1
tripleEqual.js

Double equal on the other hand only compares values, meaning different types can be equal if their value matches.

Copied to clipboard!
// Here we only check for value, therefore will return true:
'1' == 1
doubleEqual.js

When dealing with equality checks, you should always use === to test for equality, otherwise your code may contain unexpected results.

What does the triple equal operator do in JavaScript?
If you would like to see more Webtips, follow @flowforfrank

50 JavaScript Interview Questions

Resources:

  • twitter
  • facebook
JavaScript
Did you find this page helpful?
πŸ“š More Webtips
Frontend Course Dashboard
Master the Art of Frontend
  • check Access 100+ interactive lessons
  • check Unlimited access to hundreds of tutorials
  • check Prepare for technical interviews
Become a Pro

Courses

Recommended

This site uses cookies We use cookies to understand visitors and create a better experience for you. By clicking on "Accept", you accept its use. To find out more, please see our privacy policy.