Skip to content

Instantly share code, notes, and snippets.

@leosteil
Last active June 23, 2018 14:38
Show Gist options
  • Save leosteil/129637019f64e39856c7a1d368d5ad30 to your computer and use it in GitHub Desktop.
Save leosteil/129637019f64e39856c7a1d368d5ad30 to your computer and use it in GitHub Desktop.
ES6 JS - Notes
Variables:
ES5
var myVar = "Leonardo";
In ES5 variables are function-scoped
ES6
let myVar = "Leonardo;
const myConst = 1996;
In ES6 variables are block-scoped. This means that my vars are only accessible in the block scope, like an if, for, while, etc.
--------------------------------------------------------------------------------------------------------------------------------
Blocks and IIFEs:
In ES5, IIFEs are used to allow us to encapsulate our variables and methods. Now in ES6, we can do the same just using { //**// }.
And it's possible because ours variables are block-scoped.
--------------------------------------------------------------------------------------------------------------------------------
Strings:
The biggest difference in ES6 to ES5 is the tamplate strings.
ES5
var name = "leonardo";
var age = 22;
var fullInfo = "This is " + name + " and he's " + age + " years old";
ES6
const name = "leonardo";
let age = 22;
let fullInfo = `This is ${name} and he's ${age} years old`;
new string methods:
const lastName = "steil";
const n = `${name} ${lastName}`;
console.log(n.startsWith("l"));
console.log(n.endsWith("il"));
console.log(n.includes("il"));
console.log(lastName.repeat(5));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment