what is the difference between == and === in javascript? [duplicate]

2 weeks ago 20
ARTICLE AD BOX

While === (Strict Equality) compares both type and value between both operands, == (Abstract Equality aka Loose Equality) will try to convert the datatype of an operand to make both of them match before comparison.

This implicit (automatic) conversion of datatypes is called type coercion.

So for example, 5 == '5' would be true, since '5' would be implicitly converted into the number 5.

If you don't have a particular reason to use Loose Equality(==), you should default to Strict Equality(===).

Ecma's document: https://tc39.es/ecma262/multipage/abstract-operations.html#sec-islooselyequal

Read Entire Article