Variables defined inside if block, are accessible outside the if block also
console.log(name) // undefined
if (true) {
var name = "harry"
console.log(name) // harry
}
console.log(name) // harry
I got this:
if (true) {
sayHello() // hello
function sayHello() {
console.log("hello")
}
sayHello() // hello
}
sayHello() // hello
Got this too.
But what's happening here
sayHello() // TypeError: sayHello is not a function
if (true) {
sayHello()
function sayHello() {
console.log("hello")
}
sayHello()
}
sayHello()