diff --git a/1-js/06-advanced-functions/03-closure/5-function-in-if/solution.md b/1-js/06-advanced-functions/03-closure/5-function-in-if/solution.md index e2e7a91b33..7e8a698ead 100644 --- a/1-js/06-advanced-functions/03-closure/5-function-in-if/solution.md +++ b/1-js/06-advanced-functions/03-closure/5-function-in-if/solution.md @@ -1,3 +1,10 @@ -The result is **an error**. +With `'use strict'`: -The function `sayHi` is declared inside the `if`, so it only lives inside it. There is no `sayHi` outside. \ No newline at end of file +An error occurs: `ReferenceError: sayHi is not defined`. +The function `sayHi` is declared inside the block (`if`), so it only exists within that block. +In strict mode, functions declared inside a block have block-level scope, similar to variables declared with let or const. + +Without `'use strict'`: + +The function `sayHi` is accessible outside the block. This is because, in non-strict mode (and older JavaScript specifications before ES6), functions declared inside blocks like `if`, `for`, etc., +are hoisted to the nearest function or global scope, making them accessible outside the block.