mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-12 10:00:39 -04:00
fix(curriculum) : Typo in "The var Keyword and Hoisting" (#63357)
This commit is contained in:
@@ -16,7 +16,7 @@ Let's start with variables hoisting, when you declare a variable using the `var`
|
||||
```js
|
||||
console.log(x); // undefined
|
||||
var x = 5;
|
||||
console.log(5); // 5
|
||||
console.log(x); // 5
|
||||
```
|
||||
|
||||
In this code even though we use `x` before declaring it we don't get an error, instead we get `undefined`. This is because JavaScript hoists the declaration `var x` to the top of its scope but not the initialization `x = 5`. It's as if the code were rewritten like this:
|
||||
@@ -40,7 +40,7 @@ function sayHello(){
|
||||
|
||||
In this case, we can call `sayHello()` before its declaration because the entire function is hoisted to the top of its scope.
|
||||
|
||||
It's important to note that hoisting works differently with `let` and `const` declarations introduced in ES6.
|
||||
It's important to note that hoisting works differently with `let` and `const` declarations introduced in ES6.
|
||||
|
||||
```js
|
||||
console.log(y); // Throws a ReferenceError
|
||||
|
||||
Reference in New Issue
Block a user