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
| const converterOld = (toUnit, factor, offset, input) => { | |
| const converterOffset = offset || 0; | |
| return [((converterOffset + input) * factor).toFixed(2), toUnit].join(' '); | |
| }; | |
| const convert10MilesToKm = converterOld('km', 1.60936, undefined, 10); | |
| const convert20MilesToKm = converterOld('km', 1.60936, undefined, 20); | |
| const convert30MilesToKm = converterOld('km', 1.60936, undefined, 30); | |
| console.log('convert10MilesToKm : ', convert10MilesToKm); // "16.09 km" |
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
| const converterOld = (toUnit, factor, offset, input) => { | |
| const converterOffset = offset || 0; | |
| return [((converterOffset + input) * factor).toFixed(2), toUnit].join(' '); | |
| }; | |
| const convert10MilesToKm = converterOld('km', 1.60936, undefined, 10); | |
| const convert20MilesToKm = converterOld('km', 1.60936, undefined, 20); | |
| const convert30MilesToKm = converterOld('km', 1.60936, undefined, 30); | |
| console.log('convert10MilesToKm : ', convert10MilesToKm); // "16.09 km" |
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
| const playWithArray = () => { | |
| let privateArray = []; | |
| const addItem = (item) => { | |
| privateArray.push(item); | |
| } | |
| const removeItem = (index) => { | |
| privateArray.splice(index, 1); | |
| } |
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
| const counter = () => { | |
| let privateCounter = 0; | |
| const changeBy = (val) => { | |
| privateCounter += val; | |
| } | |
| return ({ | |
| increment: () => { | |
| changeBy(1); |
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
| const outerFunc = () => { | |
| // the outer scope | |
| let outerVar = 'I am from outside!'; | |
| const innerFunc = () => { | |
| // the inner scope | |
| console.log(outerVar); | |
| } | |
| return innerFunc; |
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
| const globalVar = 'global'; | |
| const outerFunc = () => { | |
| const outerVar = 'outer'; | |
| const innerFunc = () => { | |
| const innerVar = 'inner' | |
| console.log(innerVar, outerVar, globalVar); // "inner", "outer", "global" | |
| } |
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
| const outerFunc = () => { | |
| // function scope | |
| const message = 'Hi, Hela !'; | |
| { | |
| // block scope | |
| const message = 'Hello !'; | |
| console.log('inside message : ', message); // "inside message : ", "Hello !" | |
| } |
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
| const run = () => { | |
| // "run" function scope | |
| const two = 2; | |
| let count = 0; | |
| const run2 = () => { } | |
| console.log(two); // 2 | |
| console.log(count); // 0 | |
| console.log(run2); // function | |
| } |
NewerOlder