Created
April 29, 2019 17:18
-
-
Save carlosequiz/3be4436887e33edbdc9e5a84dcf67fb2 to your computer and use it in GitHub Desktop.
A Functional Programmer’s Introduction to JavaScript from Eric Elliot's Composing Software
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
// EXPRESSIONS AND VALUES | |
// A variable declared with the const keyword can’t be reassigned. This restriction is a good thing. | |
const hola = 'Hola'; | |
// TYPES | |
const arreglo = [1, 2, 3]; | |
const a = 'a'; | |
const b = 'b'; | |
const oA = { a }; | |
const oB = { b }; | |
// It iterates over the properties in oA and assigns them to the new object, | |
// then does the same for oB, overriding any keys that already exist on the new object. | |
const c = { ...oA, ...oB }; // { a: 'a', b: 'b' } | |
// If object spread operator does not work | |
const d = Object.assign({}, oA, oB); // { a: 'a', b: 'b'} | |
const e = Object.assign({}, oB, oA); // { b: 'b', a: 'a'} | |
// Mutating an existing object rather than creating a new object is usually a BUG. | |
// DESTRUCTURING | |
const [t, u] = ['a', 'b']; | |
t; // 'a' | |
u; // 'b' | |
const bleep = { | |
blop: 'blop' | |
} | |
// Equivalent to const blop = blep.blop; | |
const { blop } = bleep; | |
// COMPARISONS AND TERNARIES | |
4 + 4 === 8; // true | |
14 - 7 === 7 ? 'Sip!' : 'Nop!'; // Sip! | |
14 - 7 === 53 ? 'Sip!' : 'Nop!'; // Nop! | |
// FUNCTIONS AND SIGNATURES | |
const double = x => x * 2; | |
double(5); // 10 | |
const orZero = (n = 0) => n; | |
orZero(); // 0 | |
orZero(2); // 2 | |
// NAMED ARGUMENTS | |
const createBand = ({ | |
name = 'Anonymous', | |
avatarThumbnail = '/avatars/anonymous.png' | |
}) => ({ | |
name, | |
avatarThumbnail | |
}); | |
const exilio = createBand({ | |
name: 'Exilio', | |
avatarThumbnail: '/avatars/world-emoji.png' | |
}); | |
/* { name: 'Exilio', avatarThumbnail: '/avatars/world-emoji.png' } */ | |
// REST AND SPREAD | |
const unaCola = (cabeza, ...cola) => cola; | |
unaCola(1, 2, 3); // [2, 3] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment