Lesson 5 of 5 · 8 minutes

Naming your variables well

The computer does not care whether a variable is named x or amountToPay. People do.

A good name says what the box holds. price, tax, and total make code easier to understand than a, b, and c.

JavaScript names cannot contain spaces. Use camel case: start with a small letter and begin each later word with a capital, as in amountToPay.

The same calculation shown with vague names and clear names

Same result. Clear names make the purpose visible.

Loading the editor…

Rename p to price, t to tax, and x to total. Change every place each name appears.

Quick check

Does renaming a variable change what the program does?

Choose one answer.

Which name best describes money a customer must pay?

Choose one answer.

You can now choose names that make your code easy to read.