when you declare a variable outside the function, then it is called as a global variable. when you declare a variable with in a function, then it is called as a local variable.
JavaScript ECMA Script does not have block statements ( if , for , while) scope.
For Example:
if(true){
var x = 15;
}
console.log(x); // x is 15
where as, In ECMA script let declaration was introduced.
if(true){
let x = 15;
}
console.log(x); // x is not defined
JavaScript ECMA Script does not have block statements ( if , for , while) scope.
For Example:
if(true){
var x = 15;
}
console.log(x); // x is 15
where as, In ECMA script let declaration was introduced.
if(true){
let x = 15;
}
console.log(x); // x is not defined
No comments:
Post a Comment