tencent cloud

Variables
Last updated: 2025-03-25 11:41:05
Variables
Last updated: 2025-03-25 11:41:05

Concepts

Variables in WXS are references to values;
Variables that are not declared and used by direct assignment are defined as global variables;
If a variable is declared without being assigned a value, the default value is undefined;
var behaves in the same way as javascript, there will be variable lifting.
var foo = 1;
var bar = "hello world";
var i; // i === undefined
In the above code, three variables foo, bar and i are declared. Then, foo is assigned the value 1 and bar is assigned the string "hello world".

Variable Naming

Variable naming must conform to 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 Identifier

The following identifiers cannot be used as variable names:
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
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback