Javascript

Topic: JS Variables

How to create a JavaScript variable?

Creating a variable in JavaScript is most often referred to as "declaring" a variable.

You declare JavaScript variables with the var keyword: var carname; After the declaration, the variable is empty (it has no value).

To assign a value to the variable, use the equal sign:
carname="Volvo";

However, you can also assign a value to the variable when you declare it:
var carname="Volvo";

Browse random answers: