Error executing function

1

Because the result expected (5 * 4 = 20), does not result in this, but in undefined ?

function anyMe(callback) {
    
    callback(5,4);
    
}
var expresion = anyMe(function(a,b){
    
    return a * b;
    
});



window.addEventListener("load",function(){
     
  
    document.write(expresion);
    
},false);
    
asked by Eduardo Sebastian 27.06.2017 в 04:00
source

1 answer

2

It's simply because the function anyMe even if you execute your callback, it does not return anything, you can correct it like this:

function anyMe(callback) {    
    return callback(5,4);    
}
var expresion = anyMe(function(a,b){    
    return a * b;    
});

window.addEventListener("load",function(){
    document.write(expresion);    
},false);
    
answered by 27.06.2017 в 04:24