SHARE
TWEET

Untitled

a guest Apr 21st, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Conversion of Boolean and Numbers
  2. const isTrue  = !0;
  3. const isFalse = !1;
  4. const alsoFalse = !!0;
  5. console.log(isTrue);          // Result: true
  6. console.log(typeof true);     // Result: "boolean"
  7.  
  8. // Conversion to String
  9. const val = 1 + "";
  10. console.log(val);             // Result: "1"
  11. console.log(typeof val);      // Result: "string"
  12.  
  13. // Conversion to Number
  14. let int = "15";
  15. int = +int;
  16. console.log(int);             // Result: 15
  17. console.log(typeof int);      //Result: "number"
  18.  
  19. const int = ~~"15"
  20. console.log(int);             // Result: 15
  21. console.log(typeof int);      // Result: "number"
  22.  
  23. // Conversion from Booleans to Number
  24. console.log(+true);           // Return: 1
  25. console.log(+false);          // Return: 0
  26.  
  27. // Calculating Powers
  28. console.log(2 ** 3);          // Result: 8
  29.  
  30. // Conversion from Float to Integer
  31. console.log(23.9 | 0);        // Result: 23
  32. console.log(-23.9 | 0);       // Result: -23
  33.  
  34. // For removing Final Digits
  35. console.log(1553 / 10   | 0)  // Result: 155
  36. console.log(1553 / 100  | 0)  // Result: 15
  37. console.log(1553 / 1000 | 0)  // Result: 1
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top