Operators
String operations, mathematical operations, boolean expressions
Operators:
Operators are symbols or keywords that perform operations on variables and values. In programming, operators are used to manipulate data and perform calculations.
String Operations:
String operators are used to manipulate text. Common string operations include:
Concatenation: Joining two or more strings together.
Example: "Hello" + " " + "World" results in "Hello World".
Length: Finding the number of characters in a string.
Example: "Hello".length would return 5.
Comparison: Checking if two strings are equal or comparing them lexicographically.
Example: "apple" == "banana" results in false.
Example: (from code)
var key = "" //key
Mathematical Operations:
Mathematical operators are used to perform arithmetic calculations. Common operations include:
Addition (+): Adding two values.
Example: 5 + 3 results in 8.
Subtraction (-): Subtracting one value from another.
Example: 7 - 2 results in 5.
Multiplication (*): Multiplying two values.
Example: 4 * 3 results in 12.
Division (/): Dividing one value by another.
Example: 10 / 2 results in 5.
Modulus (%): Finding the remainder of a division.
Example: 10 % 3 results in 1.
Example: (from code)
this.positionX += speed;
frame = (frame + 1) % obj.frames;
Boolean Expressions:
Boolean operators are used to evaluate logical conditions, typically returning true or false. Common boolean operations include:
AND (&&): Returns true if both conditions are true.
Example: (5 > 3) && (4 < 6) results in true.
OR ( ): Returns true if at least one condition is true.
Example: (5 > 3) || (4 > 6) results in true.
NOT (!): Reverses the boolean value.
Example: !(5 > 3) results in false because 5 > 3 is
true, and the NOT operator negates it.
Example: (from code)
if (this.positionX > viewportWidth - this.pixels) {
}