Is it necessary to use === to compare strings in Javascript or is == enough?

Viewed 16829

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

I can understand why === is necessary when comparing numbers, booleans, empty strings, etc, due to unexpected type conversions e.g.

var foo = 1; 
var bar = true; 
// bar == foo => true
// bar === foo => false

But can == ever introduce a bug when comparing a variable to a non-empty string literal? Is it more efficient to use == over === in this case?

4 Answers
Related