top of page

Upskilling Exams

Public·11 members

var vs let vs const in JavaScript – Complete Beginner Guide

  • var is the old JavaScript keyword, function-scoped, and allows redeclaration and updating of values.

  • var is hoisted and can create bugs, so it is not recommended in modern JavaScript.

  • let is block-scoped, cannot be redeclared in the same block, and is used for variables whose values may change.

  • let is safer than var because it respects block scope and avoids accidental redeclarations.

  • const is block-scoped like let but its value cannot be changed or redeclared after assignment.

  • Use const for fixed values and let for changeable values; avoid var in modern code.

6 Views
bottom of page