Here I'm declaring a variable x as its initial value 10 and later declared a function x so it should overwrite x variable and it should log function x. But here it is throwing error as Uncaught TypeError: x is not a function.
function asas() {
// 1
var x = 10; // CHECK
// 2
function x() {}
// 3
x();
console.log(x);
}
asas();
whereas, If we don't assign anything to x as below snippet then it is taking a function as a value function x() {}. I don't understand why?
function asas() {
// 1
var x; // CHECK
// 2
function x() {}
// 3
x();
console.log(x);
}
asas();