Promotic
WikipediaLinkedInYoutubeTwitterFacebook

The JavaScript operators and syntax description

The JavaScript language expression is similar to VBScript language expression, but has more operators and therefore is more general and versatile (see Operators List of the language VBScript). The PROMOTIC system therefore prefers to use the JavaScript language expressions.
 
Comparison:
- The expression addition, subtraction, multiplication, division .. is identical in JavaScript and VBScript language, e.g.
(4 * x + 1) / 3
- The expressions for logical operations like "and", "or" .. are different, e.g.
for JavaScript: (b1 && b2) || b3
for VBScript: (b1 And b2) Or b3.
- Very handy conditional JavaScript expression (e.g. b ? 1 : 2) cannot be written in VBScript.
 
The JavaScript expressions are used in the PROMOTIC system:
- in graphic items in the E - Binding to the general expression data binding.
- in command parameters of the source file for the PmReport object - see Source file description of the PmReport object.
 
List of JavaScript expression operators:
 
Arithmetic operators:
operator Description
v1 + v2 Addition or strings addition
v1 - v2 Subtraction
v1 * v2 Multiplication
v1 / v2 Division
v1 % v2 Modulo (remainder after division v1/v2)
v1 ? v2 : v3 If v1 is true, then v2 is returned, else v3 is returned
v1++ Increment - increments a variable by one (v1=v1+1)
v1-- Decrement - decrements a variable by one (v1=v1-1)
 
Logical operators:
operator Description
v1 == v2 Returns true if v1 and v2 values are the same
v1 != v2 Returns true if v1 and v2 values are not the same
v1 >= v2 Returns true if v1 is greater or equal v2
v1 > v2 Returns true if v1 is greater than v2
v1 <= v2 Returns true if v1 is less or equal v2
v1 < v2 Returns true if v1 is less than v2
v1 && v2 Logical AND (returns true if v1 and v2 are true)
v1 || v2 Logical OR (returns true if v1 or v2 is true)
!v1 Logical NOT (returns true if v1 is false)
 
Bit operators:
operator Description
v1 & v2 Bitwise AND (each bit of the returned value is a result of AND operation of corresponding bits in v1 and v2)
v1 | v2 Bitwise OR (each bit of the returned value is a result of OR operation of of corresponding bits in v1 and v2)
v1 ^ v2 Bitwise XOR (each bit of the returned value is a result of XOR operation of corresponding bits in v1 and v2)
~v1 Bitwise NOT (each bit of returned value is the result of NOT operation of corresponding bit in v1). Not implemented in the PROMOTIC system so far.
v1 << v2 Bitwise leftshift (the bit values in v1 are shifted by v2 number of bits left). For example v1<<2 returns double the v1 value.
v1 >> v2 Bitwise rightshift (the bit values in v1 are shifted by v2 number of bits right). For example v1>>2 returns the whole number division of v1/2.
The bit operators of the JavaScript language require whole number values (4-byte integer). If the value is not a integer then the operator has to transform it to integer first. If the value cannot be transformed then the operator returns the NaN value.:
Example:
See the examples in the description of the E - Binding to the general expression data binding.
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice