Operators
Operators
is a symbol which is used to perform operations on variables and values. For example, +
is an operator used to perform addition. It tells the compiler to perform the addition of two numbers.
Arithmetic Operators
Addition Operator
- The
+
operator is used to add two numbers.
let a = 10;
let b = 20;
let c = a + b;
print(c);
Console
30
Subtraction Operator
- The
-
operator is used to subtract two numbers.
let a = 20;
let b = 10;
let c = a - b;
print(c);
Console
10
Multiplication Operator
- The
*
operator is used to multiply two numbers.
let a = 10;
let b = 20;
let c = a * b;
print(c);
Console
200
Division Operator
- The
/
operator is used to divide two numbers.
let a = 20;
let b = 10;
let c = a / b;
print(c);
Console
2
Logical Operators
Equality Operator
- The
==
operator is used to check if two values are equal.
let a = 10;
let b = 10;
print(a == b);
Console
true
Inequality Operator
- The
!=
operator is used to check if two values are not equal.
let a = 10;
let b = 20;
print(a != b);
Console
true
Less/Greater Than Operator
- The
<
and>
operators are used to check if a value is less than or greater than another value.
let a = 10;
let b = 20;
print(a < b);
print(a > b);
Console
true
false
Less/Greater Than or Equal Operator
- The
<=
and>=
operators are used to check if a value is less than or equal to or greater than or equal to another value.
let a = 10;
let b = 20;
print(a <= b);
print(a >= b);
Console
true
false