Functions that return other functions

const divide = (x, y) => x / y;
const secondArgumentIsntZero = (func) => (...args) => {
if (args[1] === 0) { //It checks the second argument
console.log('Error: dividing by zero');
return null;
}
return func(...args);
};
const divideSafe = secondArgumentIsntZero(divide);
console.log(divideSafe(7, 0));
console.log(divideSafe(5, 3));
Error: dividing by zero
null
1.6666666666666667

Sources: https://www.linkedin.com/learning/learning-functional-programming-with-javascript-es6-plus