Element | Description | Example |
Arithmetic Operators |
|
|
+ | Addition | 100 + a |
- | Subtraction | 100 - 50 |
* | Multiplication | 100 * 2 |
/ | Division | 100/5 |
% | Modulo (remainder from division) | 10 % 3 |
^ | Power (exponentiation) | 2 ^ 16 |
- | Negation (makes a number negative) | -4 |
Concatenation |
|
|
+ | Joins two strings together | "abc" + "def" |
Comparison Operators |
|
|
== | Equal to | if(Name == "Test") |
<> | Not equal to | Name <> "Test", QTY <> 3 |
>, < | Greater than, Less than | QTY > 3 QTY < 3 |
>=, <= | Greater than or equal to, Less than or equal to | QTY >= 3 QTY <= 3 |
Logical Operators |
|
|
&& | Logical AND returns true only if both conditions are true | If (age >= 18 && hasLicense ==true returns true if the customer age is greater than or equal to 18 and they have a license. |
|| | Returns true is at least one condition is true | if (isWeekend || isHoliday) returns true if the date is a weekend or a holiday |
! | NOT operator, flips true to false and false to true | If (!isRegistered) will show the registration page if the user is not registered with the system.
|
To pull these together, here is an example:
β
if ((totalAmount > 50 || hasPremiumMembership) && !cartIsEmpty && (paymentMethod == "credit" || paymentMethod == "paypal") && shippingAddress != null)
If the customer's order is $50 or more, or if the user has a premium membership, and there is something in the cart, they must use a credit card or PayPal, and the shipping address must not be null.
Element | Description | Example |
Special Operators and Elements |
|
|
= | Assignment (assigns a value to a variable) | var name = "Test" |
(statement ? iftrue : iffalse) | Conditional (Ternary Operator): Returns iftrue if statement is true, otherwise returns iffalse. | (a > 100 ? "greater" : "less") |
(type)variable | Type Casting: Converts a value to a specified data type. | (int)100.25 |
[] | Array Index: Accesses an element within an array. | 1 + arr[i+1] |
. | Member Access: Accesses properties or methods of an object. | varA.varB.function("a") |
\" | Escape Character: Used to include a double quote within a string literal. | FirstMatch(Barcodes, "BARCOD_TYP == \"UPC\"" |
Literals (Fixed Values) |
|
|
"..." | String Literal: Text enclosed in double quotes. | "string!" |
'c' | Character Literal: A single character enclosed in single quotes. | c |
true, false | Boolean Literal: Represents truth values. | true && false |
100.25D, 100.25F | Decimal/Floating-Point Literals: Numbers with decimal points. | 100.25D + 100.25F |
100 | Integer Literal: Whole numbers. | 100 |