Understand how asynchronous JavaScript works:
requestAnimationFrame
can be used to reduce the number of repaints for animations. This might benefit your application performance.Browse the internet to answer the following questions:
fetch()
not simply return the response from the server?Create an implementation of setTimeout
that returns a promise rather than taking a callback. Name this new function atFullSecond
, as it should wait for the remaining milliseconds until the next second starts. For example, at 13:23 and 441 milliseconds, atFullSecond(1)
should wait for 559 milliseconds before triggering the callback function.
Internally, it can make use of setTimeout, but the API should be like that:
atFullSecond(2).then(function() {
console.log(`waited until exactly ${new Date}`);
});
new Date().getUTCMilliseconds()
gives you access to the current millisecond offset.
As a bonus, also reject the promise if the caller passes number smaller than one to atFullSecond
.
Write a function that:
fetch()
(either as a JSON array or as a pre-rendered HTML fragment).Create three different implementations of this:
then()
async
/ await