Front end developer from Greece with professional experience in large e-commerce, administration and betting applications. Interests include: ECMAScript, Typescript, React, SEO.
Because setTimeout actually returns a positive integer ID which can be used later to cancel the timeout before it expires. This integer is returned immediately so it is effectively the same as using await on a number, e.g 'await 5'.
On the other hand, the console.log statement will be executed after 1000ms.
So the timeline of events is:
You await for an integer, it gets wrapped in an implicit Promise which is immediately resolved.
The 'then' clause is executed since the promise was resolved, you see 'finished' in the console.
1000ms pass, the timeout expires and you see the 'run first' message.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Because setTimeout actually returns a positive integer ID which can be used later to cancel the timeout before it expires. This integer is returned immediately so it is effectively the same as using await on a number, e.g 'await 5'.
On the other hand, the console.log statement will be executed after 1000ms.
So the timeline of events is:
You await for an integer, it gets wrapped in an implicit Promise which is immediately resolved.
The 'then' clause is executed since the promise was resolved, you see 'finished' in the console.
1000ms pass, the timeout expires and you see the 'run first' message.