var func = function () {
var i: number = 0;
if (i == 0) {
var y: number = 1;
}
document.body.innerHTML = y.toString(); // js/ts should complain me in this line
};
func(); // output: 1
As you can see, I've declared variable y
inside if
block. So, I think it couldn't be referenced outside the scope.
But, when I've tried to run the code, the output is 1
.
Is it an issue in typescript/javascript?