types of variables in JavaScript?

  • var → Function-scoped, can be redeclared. (Older way, avoid in modern JS)
  • let → Block-scoped, can be updated but not redeclared in the same scope.
  • const → Block-scoped, cannot be updated (immutable reference).

Example:

var x = 10; // function scoped
let y = 20; // block scoped
const z = 30; // constant

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *