Sunday, March 15, 2015

Difference between == and === in JavaScript

== converts the operands to the same type before checking for quality.
== checks only for same value.

Example

0 == false // true
2 == "2" // true
null == undefined // true
view raw gistfile1.js hosted with ❤ by GitHub

=== does not converts the operands to the same type before checking for quality.
=== checks for same value + same type. 

Example

0 === false // false
2 === "2" // false
null === undefined // false
view raw gistfile1.js hosted with ❤ by GitHub

Link of Examples
== Comparison Operator
=== Comparison Operator

No comments:

Post a Comment