console.log(a)
var a = 1;
function a(){};
var a = 10;
console.log(a)
=====================
var a = 1;
if(true){
function a(){};
var a = 10;
}
console.log(a)
both above the code snippets are the same except for the if.why block makes the last mistake when it is valid in javascript so that delcare the same variable twice in the same area with var, as shown below
function a(){};
var a=10;
Also for a slightly different scenario after removing var from `var a = 10 in the above code, then it works fine, but the output is surprising
var a = 1;
if(true){
function a(){};
a = 10;
}
console.log(a)
, , 10.. , if, , , javascript var , ... 10?
, 10, , .
var a = 1;
if(true){
var a= function(){console.log()}
a = 10;
}
console.log(a)