All variables in SJS are references to values.
Syntax rule
- Supports var (variable) hoisting as in JavaScript.
- Supports
const
andlet
as in JavaScript. - Undeclared variables are directly assigned and used, and defined as global variables.
- If a variable is declared but not assigned, its default value is
undefined
.
var num = 1;
var str = "hello alipay";
var undef; // undef === undefined
const n = 2;
let s = 'string';
globalVar = 3;
Variable name
Naming conventions
The naming of variables must conform to the following two rules:
- The first character must be a letter (a-z, A-Z) or an underline (_).
- Characters other than the first character can be letters (a-z, A-Z), underlines (_), or numbers (0-9).
Reserved identifiers
Consistent with JavaScript syntax rules, the following identifiers cannot be used as variable names:
arguments
break
case
continue
default
delete
do
else
false
for
function
if
Infinity
NaN
null
require
return
switch
this
true
typeof
undefined
var
void
while