Here’s how to declare a variable:
var x = 100;
And here’s what’s happening in the example above:
- x is the name of that variable.
- 100 is the value for the variable to store.
After you declare a variable, you can reference it by name elsewhere in your code.
var x = 100; x + 102; // Output 202
You can give an existing variable a new value at any point after it’s declared.
var weather = "rainy"; weather = "sunny"; weather; // Output "sunny"