Our Javascript Code:
Step-by-Step Breakdown
Step 1: Understand the Operators
You're using two arithmetic operators:
Operator | Description | Precedence | Associativity |
---|---|---|---|
* | Multiplication | Higher than + | Left-to-right |
+ | Addition | Lower than * | Left-to-right |
Step 2: Apply Operator Precedence
JavaScript looks at the operator precedence and starts with the higher one.
Expression:
First, multiplication (*
) has higher precedence than addition (+
), so:
Now the expression becomes:
✔ Final Answer:
A) 16
This question appeared in the TCS (Tata Consultancy Services) interview, testing the candidate’s knowledge of operator precedence in JavaScript.
Remember key Concept: Operator Precedence
JavaScript follows a strict order of operations just like in math (remember PEMDAS?):
Parentheses
Exponents
Multiplication
Division
Addition
Subtraction
So in this case:
-
Multiplication happens first (
2 * 3 = 6
) - Then addition happens (
10 + 6 = 16
)