Variables in SJS
Concepts
- Variables in SJS are references to values.
- Undeclared variables, when directly assigned, are defined as global variables.
- Variables that are declared but not assigned have a default value of
undefined
. var
behaves like in JavaScript and has variable hoisting.const
andlet
are supported, behaving like JavaScript.
// In an SJS module
var count = 110;
var bar = "hello";
// undef === undefined
var undef;
const NAME = "SJS";
let str = "string";
Variable Names
Variable names must adhere to the following two rules:
- The first character must be a letter (a-zA-Z) or an underscore (_).
- The remaining characters can be letters (a-zA-Z), underscores (_), or numbers (0-9).
Reserved Identifiers
The following identifiers cannot be used as variable names:
for
do
while
default
continue
switch
case
break
var
null
undefined
Infinity
NaN
void
delete
typeof
if
else
true
false
require
function
arguments
this
return