Vote count:
0
function add(num) {
var sum;
for (i = 1; i < num + 1; i++){
sum = (sum || 0) + i;
};
return sum;
}
add(9);
What is a keyword to describe the behavior for defining sum when it gets added to "i" in the for loop? Is this a ternary operation? Obviously the first time it loops through it is undefined, so javascript chooses 0. Why is that?
asked 44 secs ago
Operating on undefined variable
Aucun commentaire:
Enregistrer un commentaire