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 bankStatement = | |
name => | |
location => | |
balance => | |
`Hello ${name}! Welcome to the bank of ${location}. Your current balance is ${balance}`; | |
const statementExpectingLocation = bankStatement("Omer"); | |
const statementExpectingBalance = statementExpectingLocation("NYC"); | |
const bankStatementMsg = statementExpectingBalance("100 million"); // wishful thinking? |
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 a = 4; | |
let b = 5; | |
let c = 6; | |
const updateTwoVars = (a) => { | |
b++; | |
c = a * b; | |
} | |
updateTwoVars(a); | |
console.log(b,c); // b = 6, c = 24 |
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 a = 4; | |
let b = 5; | |
let c = 6; | |
const updateTwoVars = (a, b, c) => [b++, a * b]; | |
const updateRes = updateTwoVars(a,b,c); | |
b = updateRes[0] | |
c = updateRes[1] | |
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 add = (x,y) => x + y; | |
const subtract = (x,y) => x - y; | |
const multiply = (x,y) => x * y; | |
const arrayOfFunctions = [add, subtract, multiply]; | |
arrayOfFunctions.forEach(calculationFunction => console.log(calculationFunction(1,1))); // 2 0 1 |
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 functionAsObjectProperty = { | |
print: (value) => console.log(value) | |
}; | |
functionAsObjectProperty.print("mic check"); // "mic check" |
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
async function getUserToken(id) { | |
const token = await getTokenFromServer(id); | |
return token; | |
} |
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 addWrapper = () => (x,y) => x + y; | |
const add = addWrapper(); | |
const sum1 = add (1,2); // 3 | |
// Or we could do it like this | |
const sum2 = addWrapper()(4,4); // 8 |
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 timeout = () => { | |
setTimeout(() => alert("WoW"), 1000); | |
} |
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 jsonfile = require('jsonfile') | |
const file = '/tmp/data.json' | |
const obj = {name: 'JP'} | |
jsonfile.writeFile(file, obj, (err) => console.error(err)) |
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 jsonfile = require('jsonfile') | |
const file = '/tmp/data.json' | |
const obj = {name: 'JP'} | |
const errorLoggerFunction = (err) => console.error(err); | |
jsonfile.writeFile(file, obj, errorLoggerFunction) |