Skip to main content

JavaScript

Closures

  1. 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 outer init. So they are not modifying the original value at all.

JSON

  1. https://leetcode.com/problems/is-object-empty
    • Do null check as well.

Promises

  1. https://leetcode.com/problems/sleep
    • setTimeout does 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.
    • while is synchoronous, which doesn't serve the purpose of async, however compare end(current + millis) with current. new Date() is a object, use Date.now().
  2. https://leetcode.com/problems/add-two-promises
    • Do not call promises like functions.
    • Return a promise as well.