Why do we use the keyword: 'var' when the code works very well without using it.
JavaScript:
window.onload = compare;
function compare() {
cool = "45";
alert(cool +1) // I can alert it or do anything else without using 'var'
}
Here, a string is stored in 'cool' and I can do anything with it as if it was a variable. Isn't it a variable here? If it is, then what difference does the keyword 'var' makes?