I am working with promises and here is my code:
function call1() {
return new Promise(function(resolve, reject) {
resolve('resolved from call 1');
});
}
function call2(result) {
return new Promise(function(resolve, reject) {
resolve(result + ' - resolved from call 2');
});
}
function callP() {
call1()
.then(result => call2(result))
.then(function(result) {
console.log(result);
});
}
callP();
This gives me the output:
resolved from call 1 - resolved from call 2
But when I change:
.then(result => call2(result))
to:
.then(function(result) {
call2(result);
})
The result is undefined
.
As per my understanding:
function(result) {
call2(result);
}
and:
result => call2(result)
Mean the same thing. Am I doing anything wrong here?