the javascript function is not working properly

First things first; num => { num + 6 }. If you’re using curlies, you have to add the return statement. Otherwise, lose the curlies: num => num + 6. This will implicitly add a return statement.

Then, If you’re not used to working with closures, I advice you not to use arrow functions.

And while this may work

const createBase = (num) => (num) => num + 6;
let addSix = createBase(6);
console.log(addSix(10));
console.log(addSix(21));

It’s far more clear what it does for javascript beginners when you type it out like this;

const createBase = function(num) {
   return function (num) {
     return num + 6;
   }
};
let addSix = createBase(6);
console.log(addSix(10));
console.log(addSix(21));

What you had was the following, which if written out, makes it clear addSix was assigned the value of num+6 instead of being a function.

const createBase = function (num) {
    return num + 6
};

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top