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 | |
} |
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 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 = () => { | |
// 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 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 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 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 converterOld2 = (toUnit) => (factor) => (offset) => (input) => { | |
const converterOffset = offset || 0; | |
return [((converterOffset + input) * factor).toFixed(2), toUnit].join(' '); | |
}; | |
const kmConverterWithUnit = converterOld2('km'); // function with a single params | |
const kmConverterWithFactor = kmConverterWithUnit(1.60936); // function with a single params | |
const kmConverter = kmConverterWithFactor(undefined); // function with a single params | |
console.log('kmConverter : ', kmConverter); | |
console.log('kmConverter(10) : ', kmConverter(10)); // "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 universalMatcher = pattern => value => ( | |
value ? | |
(value.match(pattern)&& value.match(pattern).length >= 1 ? true : false) | |
:false | |
); | |
const floatPattern = /^[0-9]*[,.][0-9]+$/; | |
const intPattern = /^[0-9]*$/; | |
const alphaNumeric = /^[A-Za-z0-9]$/; |
OlderNewer