Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. // Implicit - Implied
  2. // Explicit - directly states, leaves no doubt
  3.  
  4. // COERCION
  5. /*
  6. Explicit coercion is simply that you can see obviously from the code
  7. that a conversion from one type to another will occur whereas implicit
  8. coercion is when the type conversion can happen as more of a non-obvious
  9. side effect of some other operation.
  10. */
  11.  
  12. // Explicit coercion:
  13. var a = "42";
  14. var b = Number( a );
  15. a; // "42"
  16. b; // 42 -- the number!
  17.  
  18. // Explicit coercion:
  19. var a = "42"; // typeof "String"
  20. var b = a * 1; // "42" implicitly coerced to 42 here
  21. a; // "42"
  22. b; // 42 -- the number!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement