Skip to content

Instantly share code, notes, and snippets.

@tonkec
Created November 8, 2019 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonkec/1fd6df5ef5335441cd2e22949e3b1a85 to your computer and use it in GitHub Desktop.
Save tonkec/1fd6df5ef5335441cd2e22949e3b1a85 to your computer and use it in GitHub Desktop.
//why is es6 important
/*
lots of syntax sugar
faster solutions
cleaner solutions
*/
// arrow functions
function sum(a, b) {
return a + b;
}
const sum = (a, b) => a + b;
// declaring variables
// let, var, const
var house = "house";
house = "pineapple";
const house = "house";
const house = "car"; // error
house = "apartment"; // error
let house = "house";
let house = "yacht"; // error
house = "mansion";
// destructuring objects
const person = {
name: "Patrick",
age: "68"
};
const { name, age } = person;
const { name, age: seniority } = person;
const person = {
name: "Patrick",
age: undefined
};
const { name, age = 70 } = person;
// destructuring arrays
const fruits = ["apple", "banana", "lemon"];
const [a, b, l] = fruits;
// assigning values
const [person1, person2] = ["Lucy", "Jim"];
// spread operator
const sum = (x, y, z) => {
console.log("x :", x);
console.log("y :", y);
console.log("z :", z);
return x + y + z;
};
const numbers = [1, 2, 3];
console.log(sum(...numbers));
console.log(sum(numbers));
const missingParts = ["itsy", "bitsy"];
const song = ["The", ...missingParts, "spider"];
// copy array
const animals = ["wolf", "dog", "cat"];
const clones = [...animals];
// template literats
const someString = "ES6 makes it even more powerful";
const whyILikeJS = `I like JS because ${someString}`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment