Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program variable


May 18, 2021 WeChat Mini Program Development Document


Table of contents


Concept

  • The variables in WXS are references to values.
  • Variables that are not declared are used directly assigned and are defined as global variables.
  • If only variables are declared and not assigned, the default value is undefined.
  • Var behaves in the same as javascript and has variable elevations.
var foo = 1;
var bar = "hello world";
var i; // i === undefined

The above code declares the three variables foo, bar, and i, respectively. The foo is then assigned a value of 1 and bar is assigned to the string "hello wolrd".

The name of the variable

Variable naming must comply with two rules:

  • The first character must be: letter (a-zA-Z), underscore (?)
  • The remaining characters can be: letter (a-zA-Z), underscore (-), number (0-9)

Keep the 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