Variable

All variables in SJS are references to values.

Syntax Rules

  • The var behaves in the same way as in JavaScript. Variable hoisting may happen.
  • The const and let are supported, which behave in the same way as in JavaScript.
  • An undeclared variable that is directly used with assignment is defined as global.
  • A variable that is declared but not used has the default undefined.
copy
var num = 1;
var str = "hello world";
var undef; // undef === undefined
const n = 2;
let s = 'string';
globalVar = 3;

Variable Name

Naming Rules

The variable name must follow these two rules:

  • The initial character must be a letter (a-z, A-Z) or underscore (_).
  • The other characters can be letter (a-z, A-Z), underscore (_) or number (0-9).

Reserved Identifier

Just like the Javascript syntax rules, the following identifiers cannot be used as variable names:

copy
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