Guest User

Untitled

a guest
Sep 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. // Spread - Operator
  2. const numbers = [1,1,2,3,5,8,13];
  3. const maxFromArray = Math.max(...numbers); // returns 13
  4.  
  5. const num1 = [1,2,3];
  6. const num2 = [4,5,6];
  7.  
  8. // this is also possible with objects
  9. const fullnum = [...num1, ...num2]; // returns [1,2,3,4,5,6]
  10.  
  11.  
  12. // Rest - Operator
  13. const makeArray = (...args) => args;
  14. const myArrayFromFunction = makeArray(1,2,3,4); // return [1,2,3,4,5]
  15.  
  16. // Destructuring
  17. // with arrays
  18. const myHobbies = ['Cooking', 'Sports'];
  19. const [hobby1, hobby2] = myHobbies;
  20. console.log(hobby1); // return 'Cooking'
  21. console.log(hobby2); // return 'Sports'
  22.  
  23. // with objects
  24. const userData = {
  25. userName: 'Igor',
  26. age: 23
  27. };
  28.  
  29. const { userName, age} = userData;
  30. console.log(userName) // return 'Igor'
  31. console.log(age) // return 23
  32.  
  33. // Template Literals
  34. const string1 = 'Hello this ist the first part of a string.';
  35. const string2 = 'And this is the second part.';
  36.  
  37. const fullString = `${string1} ${string2} I can also add here some text`;
  38. console.log(fullString); // returns 'Hello this ist the first part of a string. And this is the second part. I can also add here some strings'
Add Comment
Please, Sign In to add comment