Variables in JavaScript: Declaration, Types, Scope
Declaring Variables: var, let, const
var— function-scoped, can be redeclared and updated, hoisted withundefined.let— block-scoped, can be updated but not redeclared in the same scope.const— block-scoped, cannot be updated or redeclared; must be initialized at declaration.
var x = 10;
let y = 20;
const z = 30;
Scope of Variables
- Global scope — declared outside any function, accessible everywhere.
- Function scope — declared with
varinside a function, accessible only within it. - Block scope — declared with
let/constinside{ }, accessible only within that block.
Ready to master real-world JavaScript development?
Learn JavaScript hands-on with mentor-led, live sessions.