Guest User

Untitled

a guest
Jun 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. ## Replace var
  2. ```
  3. //declare a variable which can be reassigned to another value
  4. let name = 'my name';
  5.  
  6. //defines a variable whose value is not reassignable
  7. const PI = 3.14;
  8. ```
  9.  
  10. ## No more stress with complex strings
  11.  
  12. ```
  13. let student = {name : 'Harry', age : '18'};
  14.  
  15. //See how representing it is easier with ``
  16.  
  17. let description = `I'm a student my name is ${student.name}
  18. I'm ${student.age} years old.`;
  19.  
  20. console.log(description);
  21. ```
  22.  
  23. ## Destructuring
  24.  
  25. ```
  26. //Extracting values from an array.
  27. const axis = [10, 25, -34];
  28.  
  29. const [x, y, z] = axis;
  30.  
  31. console.log(x, y, z);
  32. //Extracting values from an object.
  33. const man = {
  34. name: 'Peter',
  35. age: '30',
  36. height: 185
  37. };
  38.  
  39. const {name, age, height} = man;
  40.  
  41. console.log(name, age, height);
  42. ```
  43.  
  44. ## Object Literal
  45.  
  46. ```
  47. name = 'Peter';
  48. age = '30';
  49. height = 185;
  50.  
  51. const man = {
  52. name,
  53. age,
  54. height
  55. };
  56. ///Creates a man object and automatically set its name, age and height properties
  57.  
  58. console.log(man);
  59.  
  60. //Prints : {name: "Peter", age: "30", height: 185}
  61.  
  62. ```
  63.  
  64. ## The Cool For Of Loop
  65.  
  66. ```
  67. const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
  68. for(let number of numbers)
  69. {
  70. console.log(number);
  71. }
  72. ```
  73.  
  74. ## Spread it
  75.  
  76. ```
  77. const weapons = ["gun", "sword", "spirit bomb"];
  78. console.log(...weapons);
  79. ```
  80.  
  81. ## Get The Rest of it
  82.  
  83. ```
  84. const weapons = ["gun", "sword","catana", "spirit bomb", "shuriken"];
  85. const [weapon1, weapon2, weapon3, ...otherWeapons] = weapons;
  86. console.log(weapon1, weapon2, weapon3, otherWeapons);
  87. function sum(...nums) {
  88. let total = 0;
  89. for(const num of nums) {
  90. total += num;
  91. }
  92. return total;
  93. }
  94. ```
Add Comment
Please, Sign In to add comment