Pages

Sunday, November 20, 2016

Double Equals Vs Triple Equals (Javascript)

w7r.blogspot.com

Are == and === different in Javascript? YES THEY ARE DIFFERENT.

Alternative Syntax Exists for a Reason

The inventors and maintainers of the Javascript language did not include the triple equals to account for typing the '=' character one too many times...

Usage of Double Equals ==

The double equals, ==, is used to compare in a flexible manner. What I mean by a flexible comparison is that type-evaluation and conversion is performed before the expression returns a True or False boolean.

Usage of Triple Equals ===

The triple equals, ===, is used to compare in a strict manner. By strict, I mean that no type conversion will take place before comparing the two arguments to the expression (a === b). If the type of variable a and variable b are different, then the triple equals will return False, no matter what. Only when the triple equals expression has two arguments, a and b, of the same type will the comparison take place, in which if the values of argument a and argument b are the same, true is returned; otherwise false is returned.

No comments:

Post a Comment