A JavaScript Nightmare

@manucastrillonm

JavaScript is a weird language

@manucastrillonm

@manucastrillonm

@manucastrillonm

@manucastrillonm

@manucastrillonm

@manucastrillonm

Ok no... Is not that weird

@manucastrillonm

Coercion

@manucastrillonm

Coercion

Forces a variable of a certain type to have the behavior of a different one.

@manucastrillonm

@manucastrillonm

Why do we need this?

@manucastrillonm

JavaScript is a non-typed language

@manucastrillonm

Duck Typing

“If it walks like a duck and it quacks like a duck, then it must be a duck”

@manucastrillonm

@manucastrillonm

Don't worry!

coercion

@manucastrillonm

Equality operator

==

@manucastrillonm

@manucastrillonm

Addition operator

+

@manucastrillonm

@manucastrillonm

Subtraction operator

-

@manucastrillonm

@manucastrillonm

Truthy and Falsy

@manucastrillonm

In a boolean context, all values are True except

  • false

  • 0

  • ""

  • ''

  • null

  • undefined

  • NaN

  • document.all

@manucastrillonm

Conclusion

@manucastrillonm

Done

JS coercion

By Manu Castrillón

JS coercion

  • 1,000