I will try to break down the pieces:
- asyncFunction is called
- console.log is called with “The code is asynchronous”
- asyncFunction returns a value and its passed down its then
- console.log is called with the value returned of asyncFunction
- asyncFunction2 is called
- asyncFunction2 returns a value
- asyncFunction.then.then will catch the resolution of asyncFunction2 promise
- console.log is called with the value returned from asyncFunction2
A few additional points:
- A promise.then will always return a promise.
- You can return a value or another promise in the .then callback and if it was a promise it will resolve and you can catch the response in the next concatenated then.
- asyncFunction2 is not executed until asyncFunction is resolved.