Please elaborate the code what happens? Intro to asynchronous javascript

function doStep1(init, callback) {
const result = init + 1;
callback(result);
}

function doStep2(init, callback) {
const result = init + 2;
callback(result);
}

function doStep3(init, callback) {
const result = init + 3;
callback(result);
}

function doOperation() {
doStep1(0, result1 => {
doStep2(result1, result2 => {
doStep3(result2, result3 => {
console.log(result: ${result3});
});
});
});

}

doOperation();

In doOperation(), doStep3(result2,result3 => {});
In the above statement, are result2,result3 parameters to the function?
If so, why result3 is not enclosed in the bracket?

Hi @vaishnavi_A.N

Not quite.
result2 is the first parameter, but the second parameter is an arrow function. result3 => {...} is the whole parameter.
The second parameter could also be written as

function (result3) {
  ...
}

So result3 is the parameter of the function that itself as a whole is the second parameter of doStep3(). :slightly_smiling_face:
When we use arrow functions and only have one parameter we can write it without any parentheses.

By the way, when you post code directly into the forum you should use “code fences”. These are three backticks on a separate line before and after your code. Otherwise the forum may remove or change some of the characters in your code and it gets hard to read it.

```
Your code
```

I hope that makes it clearer. Please ask if I can help you any more.

Happy coding,
Michael

1 Like

Perfect, U cleared my doubt, Thank u thank u so much @mikoMK.
:+1: :+1:

1 Like