Arithmetic Operators
Arithmetic operators are symbols used in programming and mathematics to perform basic mathematical operations. Here are the common ones:
- Addition (
+
): Adds two values. For example,5 + 3
equals8
. - Subtraction (
-
): Subtracts one value from another. For example,5 - 3
equals2
. - Multiplication (
*
): Multiplies two values. For example,5 * 3
equals15
. - Division (
/
): Divides one value by another. For example,6 / 3
equals2
. - Modulus (
%
): Gives the remainder of a division operation. For example,5 % 3
equals2
.
Assignment Operators
An assignment operator assigns a value to its left operand based on the value of its right operand. Here are some of them:
+=
addition assignment-=
subtraction assignment*=
multiplication assignment/=
division assignment
What is the difference between and = ?
The equality operator converts the operands if they are not of the same type, then applies strict comparison. The = strict equality operator only considers values equal that have the same type.
Logical Operators
||
The logical OR operator ||
checks two values and returns a boolean. If one or both values are truthy, it returns true
. If both values are falsy, it returns false
.
B | A | A || B |
---|---|---|
false | false | false |
true | false | true |
false | true | true |
true | true | true |
&&
The logical AND operator &&
checks two values and returns a boolean. If both values are truthy, then it returns true
. If one, or both, of the values is falsy, then it returns false
.
!
Ternary operator
The ternary operator allows for a compact syntax in the case of binary (choosing between two choices) decisions.
variable = bedingung ? wertWennWahr : wertWennFalsch;