Skip to content

Latest commit

 

History

History
53 lines (30 loc) · 1.36 KB

File metadata and controls

53 lines (30 loc) · 1.36 KB

VARIABLES

Variables are containers that hold data. They help us store, reuse, and update information in JavaScript — from simple values like numbers to complex data like arrays and objects. Think of a variable as a box with a name on it. You can put something inside it (a value), and later check or change what's inside. In JavaScript, you create these boxes using keywords: var , let , or const.

Keywords

  1. var
  2. let
  3. const

NOTE:

These 2 words will be used later

  1. hoisted Find reference for hoisted in [hositing.md]. Before reading temporal deadzone understand this concept.
  2. temporal dead zone(tdz) Find reference for tdz in [tdz.md].

VAR

  1. part ES5js
  2. function scoped
  3. can be redeclared and reassigned
  4. hoisted to top with undefined value.

LET

  1. part of latest ES6js features
  2. block scoped
  3. can be reassigned but can't be redeclared
  4. hoisted but stays in temporal dead zone(tdz)

CONST

  1. part of latest ES6js features
  2. block scoped
  3. can't be reassigned but cant be redeclared
  4. hoisted but stays in temporal dead zone(tdz)

CONCLUSION

Use Const as much as possible.
Use Let only when you plan to redeclare the value again.
Avoid Var its part of old ES script and creates bug.