Essential JavaScript

Going Further

Naming Variables

Different programming languages have different conventions for how to name variables.

In JavaScript we name variables using camel case. In camel case, all letters are lowercase unless we are starting a new word.

It's called camel case because the uppercase letters in the middle of the variable names look like the humps on a camel.

Using Camel Case

These are examples of how to take a descriptive name and turn it into camel case:

Original Descriptive NameCamel Case Variable Name
Valuevalue
Input StringinputString
Number 1number1
Customer AgecustomerAge
Shopping Cart Item CountshoppingCartItemCount
User IDuserID
Flight ETAflightETA
HTML ElementHTMLElement

Consistency

Functions and arguments follow this same rule. Always use camel case.

Your code won't break if you use another naming convention, but it will look out of place to an experienced developer. All of JavaScript's built-in functions use camel case. Keep variable names consistent and they will be easier to read.

Practice

Look at the code in the editor. The variables should all be in camel case to keep things consistent. Fix the code by converting all values to camel case.

Remember that strings are not variable names, so you don't need to change the string arguments.

Learning Goals

  • I know what naming convention JavaScript uses for variables

  • I can write descriptive variable names in camel case

Code Editor

Click "Run Code" to execute your JavaScript in a secure sandbox and see the output below.

Console Output

// Console output will appear here...

0 output lines