The initial value of totalSum is string. Thus += is doing the string concatenation. To perform the arithmetic operation, change the initial value to number (0).
Change
var totalSum = '0'; To
var totalSum = 0; Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about CollectivesStack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Explore Stack Internal The initial value of totalSum is string. Thus += is doing the string concatenation. To perform the arithmetic operation, change the initial value to number (0).
Change
var totalSum = '0'; To
var totalSum = 0; The initial value of totalSum is string. Thus += is doing the string concatenation. To perform the arithmetic operation change the initial value to number (0).
Change
var totalSum = '0'; To
var totalSum = 0; The initial value of totalSum is string. Thus += is doing the string concatenation. To perform the arithmetic operation, change the initial value to number (0).
Change
var totalSum = '0'; To
var totalSum = 0;