- Sync vs Async
- JS executes code in a synchronous manner one function at a time one statement at a time
- JS is single threaded
- that means only one statement is executed at a time.
- Asynchronous mean two or more things happening at a time. In JS that means deferring remaining execution of a function
- We need this because some operation can take be very slow:
- image processing
- file operations I/O
- HTTP Request and waiting for response
- Sometimes making huge calculations can be kinda slow
- These types of operation on our Execution Stack
Block further execution
A callback function is a function passed into another function as an argument,
which is then invoked inside the outer function to complete some kind of routine or action.
A Promise is an object representing the eventual completion or failure of an asynchronous operation.
An async function can contain an await expression that pauses the execution of the async function
and waits for the passed Promise's resolution, and then resumes the async function's execution and
returns the resolved value. Remember, the await keyword is only valid inside async functions.
If you use it outside of an async function's body, you will get a SyntaxError.
- Things we didn't cover related to ASYNC in JS
- (We'll get a course out on these two soon. Keep an eye out on the GroupSession channel in Slack)
- Where to go from here