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

Return to Answer

Post Timeline

Commonmark migration
Source Link

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.

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

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

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

added 441 characters in body
Source Link
Starx
  • 79.3k
  • 50
  • 187
  • 266

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

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

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

added 201 characters in body
Source Link
Starx
  • 79.3k
  • 50
  • 187
  • 266

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

It is happening due the parameter naming. Use the following

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

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

Source Link
Starx
  • 79.3k
  • 50
  • 187
  • 266
Loading
lang-js

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