===
and !==
over ==
and !=
.Conditional statements such as the if
statement evaluate their expression using coercion with the ToBoolean
abstract method and always follow these simple rules:
''
, otherwise trueif ([0]) {
// true
// An array is an object, objects evaluate to true
}
Use shortcuts.
// bad
if (name !== '') {
// ...stuff...
}
// good
if (name) {
// ...stuff...
}
// bad
if (collection.length > 0) {
// ...stuff...
}
// good
if (collection.length) {
// ...stuff...
}
For more information see Truth Equality and JavaScript by Angus Croll.