Code Editor
Learn

Let's dive in and see a variable in the wild. Here is how you declare a variable:

var myName = 'Arya'; console.log(myName); // Output: Arya

You can almost read it aloud: "Variable myName is equal to Arya."

Let's dissect that statement and look at its parts:

  1. var, short for variable, is the JavaScript keyword that will create a new variable for us.
  2. myName is chosen by a developer (that's you!). Notice that the word has no spaces, and each new word is capitalized. This is a common convention in JavaScript, and is called camelCase.
  3. = means to assign whatever's next to the variable.
  4. 'Arya' is the value that the equals = assigns into the variable myName.

After the variable is declared, we can print the variable with: console.log(myName). This will print 'Arya' to the console.

Report a Bug
If you see a bug or any other issue with this page, please report it here.