What is the difference between Let, var & Const in Javascript/Typescript


In JavaScript/TypeScript, let, var, and const are used for declaring variables. However, there are some differences between them:

  1. var:
    • It is function-scoped.
    • Its value can be reassigned.
    • It can be hoisted (which means it can be accessed before it is declared).
    • It does not need to be initialized when declared.
  2. let:
    • It is block-scoped.
    • Its value can be reassigned.
    • It cannot be hoisted.
    • It needs to be initialized when declared (i.e., assigned a value).
  3. const:
    • It is also block-scoped.
    • Its value cannot be reassigned.
    • It cannot be hoisted.
    • It needs to be initialized when declared.

Continue reading