All Products
Search
Document Center

Variable

Last Updated: Feb 04, 2021

All variables in SJS are references to values.

Syntax rule

  • Supports var (variable) hoisting as in JavaScript.
  • Supports const and let 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.
 
  1. var num = 1;
  2. var str = "hello alipay";
  3. var undef; // undef === undefined
  4. const n = 2;
  5. let s = 'string';
  6. 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:

 
  1. arguments
  2. break
  3. case
  4. continue
  5. default
  6. delete
  7. do
  8. else
  9. false
  10. for
  11. function
  12. if
  13. Infinity
  14. NaN
  15. null
  16. require
  17. return
  18. switch
  19. this
  20. true
  21. typeof
  22. undefined
  23. var
  24. void
  25. while