I have the code:
function func1(){
return
array.map(function(el){
return el.method();
});
}
function func2(){
var confused =
array.map(function(el){
return el.method();
});
return confused;
}
Why func1
return undefined
while func2
return good value (that i need)?
Sorry for my english.
Internally in JS engine first example looks like this,
function func1() {
return;
array.map(function(el){
return el.method();
});
};
that's why you get undefined
, don't add new line after return
, because return statement followed by a new line tells the JS intepreter that a semi colon should be inserted after that return.
function func1() {
return array.map(function(el){
return el.method();
});
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With