Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Revisions

4 of 4
Commonmark migration

It is happening due the parameter naming. The way you are using the parameters, makes a call to function called 6() which ends up being incorrect.

So, Use the following (IMO, this is what you are attempting)

var callback = function (num) {
 return num + 1; 
}
var fn = function (num) {
 callback(num);
}
fn(callback(5));

Demo

And so far for the attempt of your to create a callback function. You are only missing a return statement in the function see the result.

var callback = function (num) {
 return function(){
 return num + 1;
 }; 
}
var fn = function (callback) {
 return callback();
}
console.log(fn(callback(5)));

Demo

Starx
  • 79.3k
  • 50
  • 187
  • 266

AltStyle によって変換されたページ (->オリジナル) /