Possible Duplicate:
JavaScript === vs == : Does it matter which “equal” operator I use?
In some JavaScript if statements I’ve seen the use of === as opposed to the standard ==.
What is the difference between these? and should I be using either one of them over the other?
e.g.
if (variable == 'string') {
return;
}
compared to:
if (variable === 'string') {
return;
}
The
===is a strict comparison (also checks type), whereas the==does a more relaxed comparison.For instance:
Another example:
In particular it is very important when comparing falsy values. In Javascript all the following will be treated as false with relaxed comparison: