This file contains hidden or 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
// #1 ES6: if passing one argument you don't need to include parenthesis around parameter. | |
var kitty = name => name; | |
// same as ES5: | |
var kitty = function(name) { | |
return name; | |
}; | |
// #2 ES6: no parameters example. | |
var add = () => 3 + 2; |
This file contains hidden or 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
// Line breaks are not allowed and will throw a syntax error | |
let func1 = (x, y) | |
=> { | |
return x + y; | |
}; // SyntaxError | |
// But line breaks inside of a parameter definition is ok | |
let func6 = ( | |
x, | |
y |
This file contains hidden or 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
// #1 | |
// Before: | |
function sayHi(petSquirrelName) { console.log('Greetings ' + petSquirrelName + '!'); } | |
sayHi('Brigadier Sir Nutkins II'); // => Greetings Brigadier Sir Nutkins II! | |
// After: | |
function sayHi(petSquirrelName) { console.log(`Greetings ${petSquirrelName}!`); } | |
sayHi('Brigadier Sir Nutkins II'); // => Greetings Brigadier Sir Nutkins II! | |
// #2 |
This file contains hidden or 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 bunnyBailMoneyReceipt(bunnyName, bailoutCash) { | |
var bunnyTip = 100; | |
console.log( | |
` | |
Greetings ${bunnyName.toUpperCase()}, you have been bailed out! | |
Total: $${bailoutCash} | |
Tip: $${bunnyTip} | |
------------ |
This file contains hidden or 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 squirrelNames = ['Lady Nutkins', 'Squirrely McSquirrel', 'Sergeant Squirrelbottom']; | |
var bunnyNames = ['Lady FluffButt', 'Brigadier Giant']; | |
var animalNames = ['Lady Butt', squirrelNames, 'Juicy Biscuiteer', bunnyNames]; | |
animalNames; | |
// => ['Lady Butt', ['Lady Nutkins', 'Squirrely McSquirrel', 'Sergeant Squirrelbottom'], 'Juicy Biscuiteer', ['Lady FluffButt', 'Brigadier Giant']] | |
// To flatten this array we need another step: | |
var flattened = [].concat.apply([], animalNames); | |
flattened; |
This file contains hidden or 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 squirrelNames = ['Lady Nutkins', 'Squirrely McSquirrel', 'Sergeant Squirrelbottom']; | |
var bunnyNames = ['Lady FluffButt', 'Brigadier Giant']; | |
var animalNames = ['Lady Butt', ...squirrelNames, 'Juicy Biscuiteer', ...bunnyNames]; | |
animalNames; | |
// => ['Lady Butt', 'Lady Nutkins', 'Squirrely McSquirrel', 'Sergeant Squirrelbottom', 'Juicy Biscuiteer', 'Lady FluffButt', 'Brigadier Giant'] |
This file contains hidden or 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 values = [25, 50, 75, 100] | |
// This: | |
console.log(Math.max(25, 50, 75, 100)); // => 100 | |
// Is the same as this: | |
console.log(Math.max(...values)); // => 100 | |
/* | |
NOTE: Math.max() typically does not work for arrays unless you write it like: |
This file contains hidden or 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 myFunction(x, y, z) { | |
console.log(x + y + z) | |
}; | |
var args = [0, 1, 2]; | |
myFunction.apply(null, args); | |
// => 3 |
This file contains hidden or 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 myFunction(x, y, z) { | |
console.log(x + y + z); | |
} | |
var args = [0, 1, 2]; | |
myFunction(...args); | |
// => 3 |
This file contains hidden or 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 dateFields = readDateFields(database); | |
var d = new Date(…dateFields); | |