function waitFor(seconds) {
const now = Date.now();
const milliseconds = seconds * 1000;
while((Date.now() - now ) < milliseconds){};
console.log(`a`);
}
setTimeout(() => {
console.log('b');
}, 1000);
setTimeout(() => {
console.log('c');
}, 0);
waitFor(2);
setTimeout(() => {
console.log('d');
}, 3000);
- A: c, b, a, d
- B: b, c, d, a
- C: a, b, c, d
- D: a, c, b, d
var fnList = [];
for (var i = 0; i < 5; i++) {
fnList[i] = function () {
return i;
}
}
fnList.forEach(function(fn){
fn();
});
- A: 0, 1, 2, 3, 4
- B: 1, 2, 3, 4, 5
- C: 5, 5, 5, 5, 5
- D: 4, 4, 4, 4, 4
The lights flashing order is:
- red light flashes for 2 seconds
- green light flashes for 2 seconds
- yellow light flashes for 1 seconds
- back to the red light and continue...
folk this codepen to implement
- let defines a variable in a block scope
- let defines a variable globally
- let defines a variable locally to an entire function
- let defines a variable that can not be changed
- it uses
=>
to define - when having more than one arguments, they need to be contained in
()
- when the function body is longer than one line, it should be wrapped by
{}
- the
this
object inside the function body, is the samethis
object in the scope where the arrow function is called.
- POST has request body, GET does not
- GET has the maximum url length restriction, post body does not have a limitation
- GET request can be cached, POST cannot
- others
- 200, ok
- 304, Cache
- 404, not found
- 401, Unauthorized
- 403, Forbidden
- 500, Server Error
- 503, Service Unavailable ...
- postMessage
- jsonp
- server proxy
- server set CORS headers (
Access-Controll-Allow-Origin
) - others
Update the css for .wrapper
to clear floats in this codepen
given this fixed HTML structure:
<div class="container">
<div class="aside">Aside</div>
<div class="main">Main</div>
</div>
implement the layout below using flexbox:
requirements:
- the size of the
container
iswidth: 100%; height: 400px
- the size of the
aside
is 200x200, the size needs to be fixed when page size changes - the size of the
main
isheight: 100%
, the width needs to be responsive to page size
Fork this codepen to implement
componentDidMount()
shouldComponentUpdate()
(why it is useful for performance)componentWillReceiveProps()
...
Concretely, a higher-order component is a function that takes a component and returns a new component.
A comprehensive challenge to test the candidate.