= vs == vs === javascript code example

Example 1: != vs !== javascript

(0 ==  '0') // true
(0 === '0') // false

('' ==  0 ) // true, the string will implicitly be converted to an integer
('' === 0 ) // false, no implicit cast is being made

Example 2: javascript == vs ===

var one = 1;
var one_again = 1;
var one_string = "1";  // note: this is string

console.log(one ==  one_again);  // true
console.log(one === one_again);  // true
console.log(one ==  one_string); // true. 
console.log(one === one_string); // false.

Example 3: == vs === javascript

== Equal to (1 == 1, 1 == "1") // equal in value ("1" is a string)
=== Equal value and equal type (1 === 1 but, 1 !== "1" // not equal type

Example 4: what is differ between between three equal and two equal

false == 0    =>  true
false === 0   =>  false

0 != false    =>  false
0 !== false   =>  true

Tags: