Sciter Script syntax


 show/hide defintions.

Assignment expressions

  1. <name> = <expression>
  2. <object> . <property-name> = <expression>
  3. <array> [ <int-expression> ] = <expression>
  4. <object> [ <key-expression> ] = <expression>

All expressions on the left side of the assignments above are so called l-value expressions – expressions that can appear on the left side of the  assignment operator.

The assignment expressions allows to:

  1. assign the value to the variable given by the <name>;
  2. assign the value to the property (a.k.a. deep assignment) of an object (with creation of property, local to the object, if it does not exist), given by <property-name>;
  3. change the value of an array element at the index, given by the <int-expression>;
  4. assign or create the local property (shallow assignment) at <key-expression> of the object. Here, <key-expression> is an expression of any type.

Multi-target assignments.

TIScript also supports so called multi-target assignments that allows to assign value(s) to the group of l-values in a single assignment operation:

  1. ( <lvalue-expression> [ , <lvalue-expression> ]* ) = <expression> | ( <expression> [ , <expression> ]* )


var a,b,c;
   (a,b,c) = 1; // a, b and c will all get value 1;
   (a,b,c) = (1,2,3); // a will get 1, b - 2 and c will get value 3;
   (a,b) = (b,a); // swaps values of a and b variables.

Sequence of expressions separated by the comma ,  and enclosed by (  )  parentheses are known as <expression-list>. If all members of the list are l-value expressions then such a list is <lvlaue-expression-list>.


<expression> ? <if-true-expression> : <if-false-expression>
Executes <if-true-expression> if the <expression> evaluates to true, and <if-false-expression> otherwise.
<expression> + <expression>
<expression> - <expression>
<expression> * <expression>
<expression> / <expression>
<expression> % <expression>
Standard arithmetic operators: addition, subtraction, multiplication, division, modulo, and negation. Operands of these operators have to be one of the numeric types: integer, float or length. Addition can also be used with string operands. In this case, it will concatenate two strings into one.
<lvalue> += <expression>
<lvalue> -= <expression>
<lvalue> *= <expression>
<lvalue> /= <expression>
<lvalue> %= <expression>
Shortcut assignment with the arithmetic operation, equivalent of: <lvalue> = <lvalue> op <expression>.
++ <lvalue>
-- <lvalue>
Increment and decrement operators. These operators increment or decrement <lvalue>, and return the changed value.
<lvalue> ++
<lvalue> --
Post-increment and post-decrement operators. These operators increment or decrement <lvalue>, and return the initial value (which it had before being incremented or decremented).
<expression> == <expression>
<expression> === <expression> (strong equality)
<expression> != <expression>
<expression> !== <expression> (strong inequality)
<expression> < <expression>
<expression> <= <expression>
<expression> >= <expression>
<expression> > <expression>
Standard relational operators that evaluate to either true or false values. All expressions (except of the strong variants) compare values of operands. Strong counterparts compare the "naked" values. For example:
0 == null   evaluates to true
0 === null  evaluates to false
<expression-1> || <expresssion-2>
<expression-1> && <expression-2>
! <expression>
Standard logical (boolean) operators: or, and, and not. The result of the || operator is either the value of <expression-1> if it evaulates to not false (i.e. not null or not undefined), or the value of <expression-2>. Operators && and ! return either true or false. Examples:
(123 || 323) evaluates to 123
(0 || 323) evaluates to 323
(null || 323) evaluates to 323
(null && 323) evaluates to false
(123 && 323) evaluates to true
<expression> &= <expression> (bitwise-and)
<expression> | <expression> (bitwise-or)
<expression> ^ <expression> (bitwise-xor)
<expression> << <expression> (bitwise-shift-left)
<expression> >> <expression> (bitwise-shift-right)
<expression> <<< <expression> (bitwise-unsigned-shift-left)
<expression> >>> <expression> (bitwise-unsigned-shift-right)
<expression> (bitwise-not)
Standard (for JavaScript or Java) bitwise (binary) operators. <expression>s here must be of the integer type.
<lvalue> &= <expression>
<lvalue> |= <expression>
<lvalue> ^= <expression>
<lvalue> <<= <expression>
<lvalue> >>= <expression>
<lvalue> <<<= <expression>
<lvalue> >>>= <expression>
Shortcut assignment with binary operation above, equivalent of: <lvalue> = <lvalue> op <expression>.
typeof <expression>
The result is a symbol with the typename of the <expression> value. One of: #undefined, #nothing, #null, #boolean (for true or false values), #integer, #float, #string, #array, #object, #symbol,  #function, #date, #color, #length, #tuple and #class (for namespace and class objects). Example, following statement will print value of the obj variable if it is an object:
if ( typeof obj == #object ) stdout.printf("got an object %V\n", obj);
<expression> instanceof <class-expression>
<expression> !instanceof <class-expression> (not-an-instance-of)
Returns true if the value of the <expression> is an instance of the class returned by <class-expression>. !instanceof returns true if <expression> is not an instance of the class (on the right). Example, following statement will print value of the obj variable if it is an instance of user defined class MyClass:
if ( obj instanceof MyClass ) stdout.printf("got an object %V of class MyClass\n", obj);
new <class-name> ( [ <arguments> ] )
The new operator creates an instance of the class defined by the <class-name>. After creation, it calls t he constructor function of the class, passing it the <arguments>.
The this keyword inside body of a function refers to the object  this function was invoked with.
this function
These two keywords constitute single keyword that is reference to the function being executed. Useful for making recursive calls to a function within its own body. Inside body of anonymous function use this function is the only way to get reference to the function itself.
this super [ super super ...]
In nested functions: this super used in inner function allows to get reference to this object of outer function. Number of super‘s after the this designates number of levels up to lookup.
<expression> ( [ <arguments> ] )
– function call. The function is called if <expression> evaluates to a function. If it’s not a function, a runtime error will be generated. The result of this operator is the function return value or nothing if the function reaches the end without return. The nothing value is used in cases when the fuction has no value to return, e.g. in iterator functions used in for(var el in <function>) statement. In this case enumeration stops then the function returns nothing value.
<expression> { <object literal > }
– function call, if the <expression> evaluates to function then it is called with single paramenter – that literal object. Example, this:
     foo { one:1, two:2 }
will call function foo with the object as a single parameter, exactly as in this case: foo({ one:1, two:2 });
<expression> . <name>
Retrieves the value of the property by its name. If there is no such property, result of the expression is the value undefined.
<expression> [ <index-expression> ]
Retrieves the element value at the <index-expression> position in the <expression> – presumably an object, an array, or a class. If no such element exists, returns the undefined value.
<array-or-string> [ [<int-expression-start>] .. [<int-expression-end>] ]
A slice of a string or an array. Returns the sub-array or the sub-string from <start> (inclusive) to <end> (exclusive). If <int-expression-start> is omitted, index 0 is used, and if <int-expression-end> is omitted, then the value of .length is used. Example, following fragment will print "Spain" in stdout:
var str = "The rain in Spain";
stdout.println( str[12..] );
<expression> like <pattern-expression>
<expression> !like <pattern-expression> (not like)
<pattern> can be on of the following expressions:
  • string(pattern) or regular expression. If <expression> is a string this operator matches the string against the pattern given by the regular expression <regexp> or by the simple string pattern. String pattern is a string that contains the placeholder ‘?‘ character for any single character, and ‘*‘ for any substrings. For example, the statement "page.htm" like "*.htm" evaluates to true, while "page.htm" like "*.html" evaluates to false.
  • object. If <expression> is an object then <expression> is matched against this object-pattern-expression. Result of the expression is true if object-pattern-expression is a subset of the object. Values in pattern-object-expression may contain #any symbol that will match any value.
  • array.  If <expression> is an array and that array starts from this array-pattern-expression then the operator evalutes to true.
  • otherwise result of the like operator is equivalent to == operator.

String Operators

<string-expression> ~/ <string-splitter> (split-and-head operator)
<string-expression> ~% <string-splitter> (split-and-tail operator)
These two operators look up the substring <string-splitter> in the <string-expression>, and return either the head part of <string-expression> (from start of the string up to the <string-splitter> position) or the tail part (from the <string-splitter> position up to the end of the string). Both opeartors look for the <string-splitter> from the start of the <string-expression>. If <string-splitter> is not found, ~/ returns the <string-expression> itself, and ~% returns the empty string. Examples:
"file://something:anything.htm" ~/ ":" evaluates to the "file" string,
"file://something:anything.htm" ~% ":" evaluates to the "//something:anything.htm" string,
<string-expression> /~ <string-splitter> (reversed split-and-head operator)
<string-expression> %~ <string-splitter> (reversed split-and-tail operator)
These two operators do lookup similarly to ~/ and ~%, but from the end of the <string-expression>. If <string-splitter> is not found, /~ returns <string-expression> itself, and %~ returns the empty string. Examples:
"something.anything.htm" /~ "." evaluates to the "something.anything" string,
"something.anything.htm" %~ "." evaluates to the "htm" string.