Function Scope

By default, JavaScript is function scoped which means that variables are accessible within a function:

1
2
3
4
5
6
7
8
9
function myFunction(): void {
if (true) {
var myNumber = 1337;
}
// Variable `myNumber` can be accessed within the function although it is being used outside of its conditional if-block
return myNumber;
}

console.log(myFunction()); // 1337