A variable is a container for a value, like a number we might use in a sum, or a string that we might use as part of a sentence. In this example pressing the button runs some code. The first line pops a box up on the screen that asks the reader to enter their name, and then stores the value in a variable. The second line displays a welcome message that includes their name, taken from the variable value and the third line displays that name on the page. One special thing about variables is that they can contain just about anything — not just strings and numbers. Variables can also contain complex data and even entire functions to do amazing things.
Previous
Previous
JavaScript Math
Next
Next