0
0
Javascriptprogramming~10 mins

Arithmetic operators in Javascript - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Arithmetic operators
Start
Evaluate operands
Apply operator (+, -, *, /, %)
Calculate result
Return or store result
End
This flow shows how arithmetic operators take values, perform calculations, and produce a result.
Execution Sample
Javascript
let a = 10;
let b = 3;
let sum = a + b;
let diff = a - b;
let prod = a * b;
let div = a / b;
This code calculates sum, difference, product, and division of two numbers.
Execution Table
StepExpressionOperandsOperationResult
1a = 10--a = 10
2b = 3--b = 3
3sum = a + b10, 3Addition13
4diff = a - b10, 3Subtraction7
5prod = a * b10, 3Multiplication30
6div = a / b10, 3Division3.3333333333333335
💡 All arithmetic operations completed with given operands.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5After Step 6
aundefined101010101010
bundefinedundefined33333
sumundefinedundefinedundefined13131313
diffundefinedundefinedundefinedundefined777
produndefinedundefinedundefinedundefinedundefined3030
divundefinedundefinedundefinedundefinedundefinedundefined3.3333333333333335
Key Moments - 3 Insights
Why does division result in a decimal number instead of an integer?
In step 6, division of 10 by 3 results in 3.3333 because JavaScript division returns a floating-point number, not just integers.
Why are variables 'sum', 'diff', 'prod', and 'div' undefined before their assignment steps?
Before their assignment steps (3 to 6), these variables have no value, so they show as undefined in the variable tracker until assigned.
What happens if you try to add a number and a string using '+' operator?
The '+' operator concatenates if one operand is a string, so it joins them as text instead of adding numerically (not shown in this table).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the value of 'prod' after step 5?
A7
B30
C13
D3.3333
💡 Hint
Check the 'Result' column at step 5 in the execution_table.
At which step does the variable 'diff' get its value assigned?
AStep 5
BStep 3
CStep 4
DStep 6
💡 Hint
Look at the 'Expression' column for 'diff' assignment in the execution_table.
If 'b' was 5 instead of 3, what would be the result of 'sum' at step 3?
A15
B8
C13
D10
💡 Hint
Sum is a + b; changing b to 5 means sum = 10 + 5.
Concept Snapshot
Arithmetic operators perform math on numbers:
+ adds,
- subtracts,
* multiplies,
/ divides,
% gives remainder.
They return a new value without changing original variables.
Full Transcript
This visual execution shows how JavaScript arithmetic operators work step-by-step. Variables a and b are assigned 10 and 3. Then sum, diff, prod, and div are calculated using +, -, *, and / operators respectively. Each step shows operands, operation, and result. Variables update only when assigned. Division produces a decimal number. This helps beginners see how each operator changes values in order.