Quiz Entry - updated: 2026.06.20
How do you declare a variable in JavaScript, and what are the rules for naming one?
You declare a variable with let name = value;, where the name follows a few simple rules and the value can be reused later.
A variable is a named box for storing a value so you can refer to it again later in the program. You create one with the let keyword, optionally giving it a starting value:
let answer = 42;
let value = 1 + answer; // value is now 43
Rules for the name (simplified):
- Allowed characters: letters, digits, the dollar sign
$, and the underscore_. - It must start with a letter (not a digit).
- Names are case-sensitive —
myVarandmyvarare two different variables. - You can't use reserved keywords like
let,function, orifas a name.
Beyond the rules, programmers follow naming conventions so code reads consistently: camelCase for variables and functions (firstName, getUserData) and UPPER_CASE for constants that never change (MAX_SIZE). These aren't enforced by the language, but following them makes code far easier to read.