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 obj = {foo: 'foo', bar: 'bar'}; | |
function func() { | |
// IIFE! | |
(() => { | |
console.log(this); | |
})(); | |
} | |
let boundFunc = func.bind(obj); |
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
// Before | |
let multiplyByItself = (number) => { | |
return number * number; | |
}; | |
// After | |
let multiplyByItself = number => number * number; |
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
let multiplyByItself = number => number * number; | |
alert(multiplyByItself(2)); // 4 |
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
// The number parameter does not need to be surrounded by parentheses | |
let multiplyByItself = number => { | |
return number * number; | |
}; | |
alert(multiplyByItself(2)); // 4 |
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
// The simplest way | |
let multiplyByItself = (number) => { | |
return number * number; | |
}; | |
alert(multiplyByItself(2)); // 4 |
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 executeThis(callableParameter) { | |
callableParameter(); | |
alert('We are done here :)'); | |
} | |
executeThis(() => { | |
alert('Hi there! I am an arrow function passed as an argument, ihaaaaaaa!'); | |
}); |
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
// At the time of this writing, 1 US dollar = 0.85 Euro | |
const euro = 0.85; | |
let dollarsToEuros = (dollars) => { | |
if (dollars == 0) { | |
return 0; | |
} else { | |
return dollars * euro; | |
} |
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
// We can do this | |
let bar = (arg) => { | |
console.log('hi ' + arg + ', nice to meet you!'); | |
}; | |
// But we can't do that! | |
function bar(arg) => { | |
console.log('hi ' + arg + ', nice to meet you!'); | |
} |
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 foo(arg) { | |
console.log('hi ' + arg + ', nice to meet you!'); | |
} | |
// VS | |
let bar = (arg) => { | |
console.log('hi ' + arg + ', nice to meet you!'); | |
}; |