JavaScript
Closures
- https://leetcode.com/studyplan/30-days-of-javascript/
init++returns the old value, not the incremented one.- Inside your returned object, each method defines its own parameter named
init, which shadows the outerinit. So they are not modifying the original value at all.
JSON
- https://leetcode.com/problems/is-object-empty
- Do
nullcheck as well.
- Do
Promises
- https://leetcode.com/problems/sleep
setTimeoutdoes not return a Promise, and it doesn’t “resolve” anything on its own. It tells the browser/Node.js:Run this callback after millis milliseconds- Thats why return a promise explicitly.
whileis synchoronous, which doesn't serve the purpose ofasync, however compare end(current + millis) with current.new Date()is a object, useDate.now().
- https://leetcode.com/problems/add-two-promises
- Do not call promises like functions.
- Return a promise as well.