Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Fix) Update solution.md for task "Function in if" #3787

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
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.