Function in if
let phrase = "Hello";
if (true) {
let user = "John";
function sayHi() {
alert(`${phrase}, ${user}`);
}
}
sayHi();
The result is an error.
The function sayHi is declared inside the if, so it only lives inside it. There is no sayHi outside.
When I execute the code I don't get any error unless in strict mode, I think it can be a good idea to remind others that in order to see the error we need to add `'use strict';' at the top of our code
Function in if
When I execute the code I don't get any error unless in strict mode, I think it can be a good idea to remind others that in order to see the error we need to add `'use strict';' at the top of our code