ZZomato·BehavioralL1Machine Coding

JavaScript Fundamentals: var vs let, Closures, and Polyfills

viaLeetCode

Q&A covering:

  • var vs let: var is function-scoped and hoisted with an initial value of undefined, and allows redeclaration in the same scope. let is block-scoped, hoisted into a temporal dead zone (cannot be used before declaration), and cannot be redeclared in the same scope.
  • Closures: a function retains access to variables from its enclosing lexical scope even after the outer function has returned -- commonly used for data privacy/encapsulation and factory functions.
  • Polyfills: code that implements a feature not natively supported in the current environment/browser, letting you use modern APIs (e.g. Array.prototype.includes, Promise) on older runtimes by providing an equivalent implementation.
Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account