Skip to content

Instantly share code, notes, and snippets.

@mrbalihai
Created November 7, 2020 20:25
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 mrbalihai/92fae6e554bc68fc4beb073a7c4d510e to your computer and use it in GitHub Desktop.
Save mrbalihai/92fae6e554bc68fc4beb073a7c4d510e to your computer and use it in GitHub Desktop.
Code examples for mrbalihai.github.io/2016/01/24/making-the-most-of-es6.html
var myArray = [1, 2, 3, 4, 5, 6],
add = function (a, b) {
return a + b;
},
getTotal = function (arr) {
return arr.reduce(add, 0);
};
getTotal(myArray); // => 21
const myArray = [1, 2, 3, 4, 5, 6],
add = (a, b) => a + b,
getTotal = (arr) => arr.reduce(add, 0);
getTotal(myArray); // => 21
function varTest() {
var x = 31;
if (true) {
var x = 71; // same variable!
console.log(x); // 71
}
console.log(x); // 71
}
function letTest() {
let x = 31;
if (true) {
let x = 71; // different variable
console.log(x); // 71
}
console.log(x); // 31
}
var sausage = 'cumberland';
console.log(`my favourite sausage is ${sausage}`);
// => 'my favourite sausage is cumberland'
var a = 1, b = 2;
console.log(`a + b = ${a + b}`);
// => 'a + b = 3'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment