Could someone explain variables to me



<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>


Replace this line with your code.

<do not remove the three backticks above>


Variables are user-defined (meaning that you give it a name), human readable symbols we use in code to represent information (data) such as numbers, strings, input from a user, responses back from the server, etc.

Why? Imagine trying to write code that works with only literal values such as true, 10, or Tonya. Your code becomes hard to work with and its not reusable for other values. Right?

Variable allow us to write more expressive, readable, and reusable code that doesn’t have to tied directly to one value or one piece of information.

We can write a program that takes variable information and then processes it.

For example, if you have a form where you want to get a response from the person viewing the web page, you could have him/her fill out the form field and then grab that variable information within your code. Maybe you want them to select their age. Their age could be 18, 30, or 55. It’s variable.

In JavaScript, you declare your variable by giving it a human readable name, such as age. Use the keyword var to let JavaScript know “Hey, I’m creating a new variable and I’m calling it age.”

Then use the equal sign to make an assignment for the value you want that new variable to represent.

You can learn more about variables here in in the lesson on Variables and on MDN:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.