HTML CSS JavaScript SEO Python Posts Privacy About Contact

JS Variables

JavaScript variables are containers for storing data values.

Variables are named containers that store values you can reuse throughout your program. JavaScript gives you three keywords to declare them.

KeywordReassignableScopeUse When
const❌ NoBlockValue won’t change (recommended default)
let✅ YesBlockValue will change
var✅ YesFunctionOld code — avoid in modern JS

Try It — Variables in Action

Preview

Variable Naming Rules

  • Must start with a letter, $, or _
  • Can contain letters, digits, $, _
  • Case sensitivenameName
  • Cannot be a reserved keyword (let, if, return, etc.)

Tip: Good variable names describe what the value means: userName, totalPrice, isLoggedIn. Avoid single letters like x or vague names like data.