Coding Manifestation Logo
Lesson 5

Naming Rules

Good variable names make your code easy to read and understand. Follow these rules to name your variables in JavaScript.

Can contain letters,digits, _ and $Cannot start witha digitlet userName = "Vivek";Case-sensitiveShould be meaningful
  • userNamecamelCase (recommended)
  • user_namesnake_case
  • $priceStarts with $
  • _countStarts with _
  • total2Can include digits (not at start)
  • 2userCannot start with a digit
  • user-nameHyphens are not allowed
  • user nameSpaces are not allowed
  • letCannot use reserved keywords
  • @valueSpecial characters not allowed
  1. 1Can contain letters (a–z, A–Z), digits (0–9), _ and $
  2. 2Cannot start with a digit
  3. 3Case-sensitive (myVar and myvar are different)
  4. 4Cannot use reserved keywords
  5. 5Should be meaningful and descriptive

These are JavaScript keywords. You cannot use them as variable names.

letconstvarfunctionreturnifelseforwhileclassnewswitchcasebreakcontinuedefaulttrycatchfinallythrowtypeofinstanceofinof

Check if the following variable names are valid.

Variable NameValid?
firstName
1stName
user_name$
user-name
let

Use camelCase for variables. It is the most common convention in JavaScript.

let totalAmount = 250;

Try creating valid variable names.

JavaScript
PrevNext