Can someone explain why first function is running not the second one when I call it?
{
function a() {
console.log('first function')
}
}
function a() {
console.log('second function')
}
a()
If we declare them in a global scope they behave as expected, but inside block scope it's completely different. Why?
function a() {
console.log('first function')
}
function a() {
console.log('second function')
}
a()
The global function delaration move the function to top (hoisting), the one in the block stays at place.
The below result is from Edge 103.0.1264.37.
a(); // second
{
function a() {
console.log('first function')
}
}
a(); // first
function a() {
console.log('second function')
}
a(); // first