Javascript function : I recently started learning Javascript.
I have an assignment for my class, and what I have to do is to click a button (a number 10 is written on the button), and there has to be "Result = 55". (here all numbers from 0 to 10 are added)
To change words by clicking buttons, I wrote code like this.

function myFunction(num) {var p = document.getElementById("mydata); for (var i = 0; i <= num; i++) {sum = sum + i; p.innerHTML = "Result = " + sum;}              }

As I submit an assignment for school, I learned that I have to add "var sum = 0" above "var p = document.getElementById("mydata")". However, I do not understand what "var sum = 0" means.
As for looks already show when to begin and end calculating, I feel like it doesn't have to be there.