Programming Examples

Are you a Programmer or Application Developer or a DBA? Take a cup of coffee, sit back and spend few minutes here :)

Tag Archive for ‘Unary Operator’

JavaScript 002 – Calculation via Expression

JavaScript Expression Evaluation

In JavaScript, you can perform arithmetic by forming the expressions. When making the expression, you can use binary operators like addition (+), subtraction (-), multiplication (*) and division (/). We call them as a Binary Operator as it operates on two variants. Now look at the expression below:

10 – 4 * 2

You may expect the result is 12. But the result is 2. Because here Operator Precedence comes into picture. The operator * and / play higher priority than the + and – operators. In the above expression, the binary operation * is figured out on the operands 4, 2. Then the binary operation minus is done on the operand 10 and 8 giving up the result as 2. In the above expression, we used only the constant values. But one can use the variables also as an operand.

Continue Reading →