Green Files

What is the difference between the == and === operators in JavaScript?

Day: 05/31/2022 - Time: 16:18:31

The == operator compares by "result" so to speak, that is, as JavaScript is not strongly typed, it converts what you are trying to compare and checks, that is:

if (true == 'true')  // is going to be true
if (true == '1')     // is going to be true
if (true == true)    // is going to be true
if (true === 'true') // is going to be false
if (true === '1')    // is going to be false
if (true === true)   // is going to be true

The === operator compares the value and the type, so it will only be true if it is both exactly the same (value and type).

Reference:

https://pt.stackoverflow.com/questions/7/qual-a-diferen%c3%a7a-entre-os-operadores-e-em-javascript

GO UP
GO TO INDEX