Functions as data/
Mon Jul 18 2022 19:56:44 GMT+0000 (Coordinated Universal Time)
Saved by
@cruz
#javascript
const checkThatTwoPlusTwoEqualsFourAMillionTimes = () => {
for(let i = 1; i <= 1000000; i++) {
if ( (2 + 2) != 4) {
console.log('Something has gone very wrong :( ');
}
}
};
// assigning a function to a variable
isTwoPlusTwo = checkThatTwoPlusTwoEqualsFourAMillionTimes;
isTwoPlusTwo();
console.log(isTwoPlusTwo.name);
/// function as Parameters
const addTwo = num => {
return num + 2;
}
const checkConsistentOutput = (func, val) => {
let checkA = val + 2;
let checkB = func(val);
if (checkA === checkB){
return checkB;
}else{
console.log('inconsistent results');
}
}
console.log(checkConsistentOutput(addTwo, 5));
content_copyCOPY
Comments