English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
JavaScript-Anweisungen und Variablendeklarationen
varA statement declares a variable and selects whether to initialize it with a value.
Variables are containers used to store information.
Creating a variable in JavaScript is called "declaring" a variable:
var city;
After declaration, the variable is empty (has no value).
To assign a value to a variable, use the equal sign (=):
city = "New Delhi";
You can also assign a value to a variable when you declare it:
var city = "New Delhi";
Var declarations, regardless of where they appear, are processed before any code is executed. This is calledHoisting.
If you redefine a JavaScript variable, it will not lose its value.
You can find ourJavaScript variable tutorialandIn the JavaScript scope tutorialLearn more about variables.
var identifier = value;
var city = "New Delhi";Testen Sie es heraus‹/›
All browsers fully support the var statement:
Anweisung | |||||
var | ist | ist | ist | ist | ist |
Parameter | Beschreibung |
---|---|
identifier | Bestimmen Sie den Namen der Variable. Es kann jeder gültige Identifikator sein. Variablennamen können Buchstaben, Ziffern, Unterstrichen und Dollarzeichen enthalten.
|
value | Der Standardwert der Variable kann jeder gültige Ausdruck sein. Standardwertundefined |
JavaScript-Version: | ECMAScript 1 |
---|
Deklarieren und initialisieren Sie drei Variablen:
var x = 10, y = 15, z = 5;Testen Sie es heraus‹/›
Initialisieren Sie mehrere Variablen:
var x, y, z;// Variable deklarieren x = y = z = 10; // Variable initialisierenTesten Sie es heraus‹/›
JavaScript-Tutorial:JavaScript-Variable
JavaScript-Tutorial:JavaScript-Scope