I`m a beginner reading a tutorial about Dates in JavaScript, and it gives this example to compare the time between two events.
I don't really understand why firstDate and var secondDate wouldn't be the exact same time? does the new Date object in var secondDate only take the time once doEvent is triggered, whereas firstDate takes the time with window.onload?
Also, why would the variable firstDate not have the "var" tag, while variable secondDate does? would that be just a typo by the author, or is it significant in some way?
var firstDate;
window.onload=startTimer;
function startTimer(){
firstDate = new Date();
document.getElementById("date").onclick=doEvent;
}
function doEvent() {
var secondDate = new Date();
alert((secondDate - firstDate) / 1000);
}