Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Replace var
- ```
- //declare a variable which can be reassigned to another value
- let name = 'my name';
- //defines a variable whose value is not reassignable
- const PI = 3.14;
- ```
- ## No more stress with complex strings
- ```
- let student = {name : 'Harry', age : '18'};
- //See how representing it is easier with ``
- let description = `I'm a student my name is ${student.name}
- I'm ${student.age} years old.`;
- console.log(description);
- ```
- ## Destructuring
- ```
- //Extracting values from an array.
- const axis = [10, 25, -34];
- const [x, y, z] = axis;
- console.log(x, y, z);
- //Extracting values from an object.
- const man = {
- name: 'Peter',
- age: '30',
- height: 185
- };
- const {name, age, height} = man;
- console.log(name, age, height);
- ```
- ## Object Literal
- ```
- name = 'Peter';
- age = '30';
- height = 185;
- const man = {
- name,
- age,
- height
- };
- ///Creates a man object and automatically set its name, age and height properties
- console.log(man);
- //Prints : {name: "Peter", age: "30", height: 185}
- ```
- ## The Cool For Of Loop
- ```
- const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
- for(let number of numbers)
- {
- console.log(number);
- }
- ```
- ## Spread it
- ```
- const weapons = ["gun", "sword", "spirit bomb"];
- console.log(...weapons);
- ```
- ## Get The Rest of it
- ```
- const weapons = ["gun", "sword","catana", "spirit bomb", "shuriken"];
- const [weapon1, weapon2, weapon3, ...otherWeapons] = weapons;
- console.log(weapon1, weapon2, weapon3, otherWeapons);
- function sum(...nums) {
- let total = 0;
- for(const num of nums) {
- total += num;
- }
- return total;
- }
- ```
Add Comment
Please, Sign In to add comment