JavaScript Tutorial

The language for programming web pages.

JS Variables

JavaScript Variables

Variables are containers for storing data values. In JavaScript you can declare variables with var, let, or const.

Comparison:

varletconst
ScopeFunctionBlockBlock
ReassignYesYesNo
HoistingYesNoNo
RedeclareYesNoNo

Best Practice: Use const by default, use let only when you need to reassign. Avoid var.

Try It Yourself

Edit the code below and click Run to see the result live.

Source Code
Result
Topics