almost all javascript books said that
always use var keyword when you declare variables, because without var, the variable will be declared as global variable.
then, why not remove var keyword, make default declaration as local scope? like Python, if you want to use global variables, you write:
global foo;
we use local variables almost all the time, don't we? is there a good reason? Thanks for any help.
edit: Thanks for all your help, I thought there must be a good reason shows that using var is better, so I was not attempting to change the language what it was like.
var globalInt = 5;
function Hello()
{
// Hey, give me back my var keyword!
// I want to assign a global existing variable
globalInt = 7;
}
Another point is there is no easy way to remove something from JavaScript. Every feature (even hacks) is already used on thousands of sites and removing features will break those sites. JavaScript can only be extended. Or new JS should be created which will be incompatible with previous versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With