var VS let VS const

The main difference:

  1. var declarations are globally scoped or function scoped whileletandconstare block scoped.

  2. var variables can be updated and re-declared within its scope; let variables can be updated but not re-declared; const variables can neither be updated nor re-declared.

  3. They are all hoisted to the top of their scope but while var variables are initialized with undefined, let and const variables are not initialized.

  4. While var and let can be declared without being initialized, const must be initialized during declaration.

Last updated

Was this helpful?