As Kyle mentioned earlier, using a double-equal operator in a Boolean comparison can lead to issues. In some cases a Boolean conversion will occur. In other cases it will not. These inconsistencies are why Kyle recommends avoiding this usage.
(upbeat funky music)…- [Instructor] We have been talking about…some various forms of implicit coercion…and particularly we had focused…on this || and && operator that we see here.…And we revealed, essentially, that they are the equivalent…of using the ternary operator form,…which really tries to emphasize this idea…that a && "456" is going to test only the "a" variable…and if it's true, it's going to, in this case,…pick the "456" and if it's false or falsy,…it's going to pick whatever "a" was.…
So our goal here is to sort of try…to train ourselves to think about that…and I think a lot of people…kind of instinctually already use the operators that way,…but might not have actually thought,…"how is it resulting in the value?"…rather than resulting in a true or false.…So this kind of clears it up.…It's not exactly the same, but it is very, very close…to the same idiom so I think it's helpful…to think about ternary in that way.…Okay.…I think that hopefully addressed...…
There were questions in the chat right before the break…
Note: This course was created by Frontend Masters. It was originally released on 8/29/2015. We're pleased to host this training in our library.
- Primitive types: undefined, string, number, boolean, and object
- Special values: NaN and negative zero
- Natives: Regex and date
- Functions: toString, toNumber, and toBoolean
- Implicit coercion
- Explicit coercion
- Strings, numbers, and booleans
- Operators: Double equal and triple equal