Kyle walks through the worst possible offenders with implicit coercion. These are the cases where the result of the coercion is completely unexpected. He leaves the audience with a few practical takeaways and best practices.
(Upbeat music)…- [Kyle] I went looking for the worst…possible offenders, if you will.…I went trying to find the worst edge cases, if you will,…the places that you would create test cases…or unit tests, or something.…I went trying to look for the worst cases…that I could find in all of these…different value coercions.…And I essentially made this list…of the worst possible offenders here.…So, you notice I've got empty or,…the string zero, double equal to null.…
And I've got the string zero double equal…to undefined and so forth.…So I have these different things listed here…and the result there is in the comments.…So, looking at line one, string zero…double equal to null, they're not equal to each other,…and that's a good thing because it ends up being false.…If you looked objectively at those two values,…you would say, they are not the same value.…They are not the same representation of the same value,…and therefore it would make sense…that they're not equal to each other.…They're not coercively equal.…In fact, if you remember when I said at the very beginning…
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