What is an expression?
A valid combination of operators and operands is known as an expression, on evaluation, it yields results. An expression contains two elements, they are operators and operands.
2+2 //4 2*2+2 //6
Here, ‘+’ and ‘*’ is an operator and ‘2’ is an operand. When we give this expression to the computer, the computer understands this expression and it evaluates this expression. The first expression performs the addition operation. Similarly, the second expression performs multiple and additional operations. Hence, both expressions are valid expressions.
+ 2 2 * + 2 * + 2
In the above expression, When we give this type of expression the computer doesn’t understand, what to do with the expression and how this should be evaluated. Hence, both expressions are In-valid expressions. Because we have not given a valid combination of operators and operands. On the evaluation of this expression, we don’t get any results.
Operators in any programming language are broadly categorized into three types they are:
- Unitary Operators: accept only one operand
- Binary Operators: It accepts two operands. ex: *, %, -, +
|L-||Logical Operators||&&, ||, !|
|A –||Arithmetic Operators||+, -, *, /, %|
|R –||Relational Operators||<, >, <=, >=, ==, !=, ===, !==|
|A –||Assignment Operators||=, SHA/AA : (+=, -=, /=)|
|B –||Bitwise Operators||&, |, ~, ^, <<, >>|
|I –||Increment and Decrement Operators||++, —|
|C –||Conditional Operators||(condition ? if true : if false)|
|S-||Special Operators||typeof, new, delete, comma etc.|