Created
November 7, 2020 20:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myArray = [1, 2, 3, 4, 5, 6], | |
add = (a, b) => a + b, | |
getTotal = (arr) => arr.reduce(add, 0); | |
getTotal(myArray); // => 21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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