During my research, I came across a website that teaches a few best practices for Javascript programmers.
Here are some of them:- only javascript 1.7 have block scope. Hence its a very good idea to put this code in the script definition:
<script type="text/javascript" version="1.7">
- define variables with 'var', to differentiate variable's scope
global var:
var x; //global
x =0;
function init()
{
var x = 5;
alert(x); // shows 5
}
alert(x); // shows 0
No comments:
Post a Comment