Skip to content

Variable

Concept

  • Variables in WXS are references to values.

  • Undeclared variables are directly assigned and used, and will be defined as global variables.

  • If you only declare a variable without assigning a value, the default value is undefined.

  • The performance of var is consistent with javascript, and there will be variable promotion.

js
var foo = 1;
var bar = "hello world";
var i; // i === undefined

In the above code, three variables foo, bar, and i are declared respectively. Then, foo is assigned the value 1, and bar is assigned the string 'hello world'.

Variable name

Variable naming must comply with the following two rules:

  • The first character must be: letter (a-zA-Z), underscore (_);

  • The remaining characters can be: letters (a-zA-Z), underscore (_), numbers (0-9).

Reserved identifiers

The following identifiers cannot be used as variable names:

js
delete
void
typeof

null
undefined
NaN
Infinity
var

if
else

true
false

require

this
function
arguments
return

for
while
do
break
continue
switch
case
default