What is Type coercion?
Explicit coercion / Type casting: developer intentionally converting value types
1
2
3var x = 10;
var str = x.toString();Implicit coercion / Type coercion: Type automatically converted by the JavaScript engine regardless of developer intent.
1
2
3
4
5var x = 10;
var str = x + '';
// x = Number 10, str = Sring 10Does reassignment occur when type coercion occur?
No. It only takes a moment to type when evaluating expressions.
The developer can use implicit type conversion intentionally.