In most cases, Boolean implicit coercion occurs when performing conditional logic. For example, using a Number or String variable inside an if statement. Kyle talks about Boolean implicit coercion and warns the audience about using a double-equal operator in a Boolean comparison.
(japanese music)…- Booleans also happen, if we say if foo…which foo is one, two, three,…now the if statement requires a Boolean.…So if I say if foo and I give it something non-Boolean…it's going to implicitly coerce it.…And in this case, it is always going to coerce it…with the to Boolean operation…when it's by itself.…There is definitely some foot guns like with line ten…which we'll get to in a minute.…But line two is going to force a to Boolean coercion…and that's just gonna do a simple lookup.…
- [Man] And that's a bold statement.…
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