Asynchronous / Synchronous JS Flashcards
Is JavaScript single-threaded?
Yes.
It is also synchronous (processes one operation at a time).
Blocking.
Why is JS running in the browser important?
Browsers have a BUNCH of APIs we can use that are async and enable us to keep looking at a cute cat photo while those operations are being processed asynchronously.
Is the DOM an API?
The DOM is essentially the API one uses to manipulate an HTML (or XML) document – usually using JavaScript.
The DOM is not something that comes with JavaScript.
What did jQuery provide?
Cross browser compatibility.
Are setTimeout and setInterval part of the JavaScript specification?
No, but most environments include them.. like all browsers and Node.js
How are callbacks used?
Wait for something to happen, and then do something else.
What is a Higher Order Function?
A function that takes another function as an argument.
Ex. addEventListener( ‘click’, callback).
addEventListener() is the higher order function.
What is a callback?
The function that is passed in as an argument in a higher order function.
(Callbacks are not really “a thing” in JS, just a convention).
What is a Promise?
An object that represents the eventual completion or failure of an async operation and its value.
AKA, an object that may have a value in the future.
Like a placeholder.
Possible states of a promise.
3 States.
-Pending: initial state, neither fulfilled nor rejected.
-Fulfilled: meaning that the operation was completed successfully.
-Rejected: meaning that the operation failed.
.then()
A promise object method that runs after the promise “resolves”.
.then(value)
Whatever value the promise object has gets passed as an argument.
What does the fetch() browser API return?
A promise.
T or F: JS is a language that can only do what the hosting environment allows?
True.