I'm learning JavaScript I had to face this behavior using the initial and unreliable variables. For example,
// is not an initial sum initialized; For (var i = 0; i <10; i ++) {sum = sum + i; } Alert (amount); Output: 90
< Div class = "snippet-code">
// initial var sum = 0; For (var i = 0; i <10; i ++) {sum = sum + i; } Alert (amount); Output: 45
Can anyone explain to me what is happening here? I think 45 times in the initial variable amount, it seems like this.
Edit: Try to run the code separately.
No comments:
Post a Comment