var

Summary

Declares a variable with the external type. The variable can optionally be initialized to a value.

Syntax

var name1[= value1 [, name2 [, name3 ... [, nameN]]]];

Parameters

nameN
The name for the variable. This can be any valid identifier.
valueN
Optional. Initializes the variable to a value. This can be any valid expression.

Description

The var keyword declares variable(s) with the external type. The scope of the variable is the nearest block; if no block is present, the variable will be scoped to the file's top-level scope.

For more information on variable declarations, consult the documentation for variable declarations.

Examples

Declaring an external variable
1
var foo;
Declaring multiple external variables in one statement
1
var foo, bar, baz;
Declaring and initializing an external variable
1
var foo = 1;
Declaring and initializing multiple external variables in one statement
1
var foo = 1, bar = 2, baz = "3";
Importing jQuery and memoizing a selector
1
2
3
4
5
6
7
8
// jQuery declares two symbols: 'jQuery' and '$' so we import both by convention
external jQuery, $;
 
// Use "var" and memoize the jQuery selector like you would in JavaScript
var $myElement = $("#myElement");
 
// Auto-magically works with JS++ types
string text = $myElement.text();

See Also

Share

HTML | BBCode | Direct Link