mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
fix(curriculum): resolve hoisting transcript errors (#59885)
This commit is contained in:
+2
-2
@@ -35,7 +35,7 @@ x = 5;
|
||||
console.log(x); // 5
|
||||
```
|
||||
|
||||
Function hoisting works a bit differently. When you declare a function using the `function` declaration syntax both the function name and the function body are hoisted. This means you can a function before you've declared it in your code. Here's an example of function hoisting:
|
||||
Function hoisting works a bit differently. When you declare a function using the `function` declaration syntax both the function name and the function body are hoisted. This means you can call a function before you've declared it in your code. Here's an example of function hoisting:
|
||||
|
||||
```js
|
||||
sayHello(); // "Hello, World!"
|
||||
@@ -56,7 +56,7 @@ let y = 10;
|
||||
|
||||
These declarations are hoisted but they are not initialized and you can't access them before the actual declaration in your code. This is often referred to as the temporal dead zone.
|
||||
|
||||
Understanding hoisting can help you write cleaner, more predictable code. However, relying on hosting can make your code harder to read and maintain. As a best practice, it's recommended to declare your variables at the top of their scope and your functions before you use them regardless of hoisting. This make your code's behavior more explicit and easier for other including your future self to understand.
|
||||
Understanding hoisting can help you write cleaner, more predictable code. However, relying on hoisting can make your code harder to read and maintain. As a best practice, it's recommended to declare your variables at the top of their scope and your functions before you use them regardless of hoisting. This make your code's behavior more explicit and easier for other including your future self to understand.
|
||||
|
||||
# --questions--
|
||||
|
||||
|
||||
Reference in New Issue
Block a user