JS-013
Naming Variables explained in a JavaScript learning illustration — Choose good names
Beginner2 min~2 min read#variables#naming#best-practices

Naming Variables

Choose good names

Goal

Learn how to choose clear and meaningful variable names.

Explanation

  • A variable name should explain what it stores.
  • The clearer the name, the easier the code is to read.
  • Good names help you understand your own program days later.
  • Usually English words that describe the data are used: age, userName, price.
  • Avoid meaningless names like x, abc, or test when they explain nothing.

Analogy

A label on a box should immediately explain what is inside. 'userName' is much better than just 'x'.

Code

let userName = "Vitalii";
let age = 42;

console.log(userName);

Result: Vitalii

Common mistake

Beginners often use x, a, test, or abc. This quickly makes code hard to understand.

Remember

  • The name should describe the data.
  • Use clear English words.
  • Good names make code readable.

Quick Quiz

Which variable name best describes a user's name?

Resources