Skip to main content

Variables: Naming Values

beginner12 min readLesson 28 of 143

let and const — how programs remember. Name a value once, reuse it everywhere, and learn the one rule professionals follow by default.

A variable is a named box for a value. Instead of repeating data, you store it once and refer to it by name.

Declaring variables

const courseName = "Web Development Beginner";
let lessonsDone = 0;

lessonsDone = 1; // let — value can change
  • const declares a variable that cannot be reassigned.
  • let declares one that can.

The professional default: const

Use const for everything, and switch to let only when you actually reassign. This makes code self-documenting: when a reader sees const, they know the value never flips out from under them.

const price = 19.99;
let total = 0;

total = price * 2; // fine — total is let
price = 9.99; // TypeError! const cannot be reassigned

Names matter

Names are lowercase, descriptive, and use camelCase (first word lowercase, later words capitalized):

const firstName = "Ada"; // good
const x = "Ada"; // legal but meaningless
const first_name = "Ada"; // legal but not the JS convention

Using variables

Once declared, the name is the value:

const learner = "Ada";
console.log("Hello, " + learner + "!"); // Hello, Ada!
console.log(`Hello, ${learner}!`); // Hello, Ada!  ← template literal

The second line is a template literal: backticks around the text, with ${ ... } slots that drop variable values right into the string. You will use these constantly.

What you learned

  • Variables are named values: const (default) and let (reassignable)
  • camelCase names that describe the value
  • Template literals: ${variable} slots inside backtick strings

Next: the kinds of values variables can hold.

Now practice

Variables: Naming Values — PracticeHands-on practice for “Variables: Naming Values”: apply what you just learned in js-variables.3 challenges · · ~5 min