Javascript – Why 3 equal symbols in boolean comparisons?

javascriptsyntax

Possible Duplicate:
Javascript === vs == : Does it matter which “equal” operator I use?

Why do I see lots of javascript code lately with expressions that look like this:

if(val === "something")

Why "===" instead of just "=="? What's the difference? When should I use one or the other?

Best Answer

The === does not allow type coercion, so something like this would return false:

if (2 === '2') // false

The "normal" javascript == operator does allow type coercion, and so this would return true:

if (2 == '2') // true