Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Implicit - Implied
- // Explicit - directly states, leaves no doubt
- // COERCION
- /*
- Explicit coercion is simply that you can see obviously from the code
- that a conversion from one type to another will occur whereas implicit
- coercion is when the type conversion can happen as more of a non-obvious
- side effect of some other operation.
- */
- // Explicit coercion:
- var a = "42";
- var b = Number( a );
- a; // "42"
- b; // 42 -- the number!
- // Explicit coercion:
- var a = "42"; // typeof "String"
- var b = a * 1; // "42" implicitly coerced to 42 here
- a; // "42"
- b; // 42 -- the number!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement