Skip to content

Commit 5cf65a7

Browse files
authored
Merge pull request #324 from 2400030303/improve-readme-format
Improved Hoisting Explanation and Fixed Markdown Formatting
2 parents 9b208be + 9212863 commit 5cf65a7

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,33 +1364,34 @@
13641364
13651365
26. ### What is Hoisting
13661366
1367-
Hoisting is a JavaScript mechanism where variables, function declarations and classes are moved to the top of their scope before code execution. Remember that JavaScript only hoists declarations, not initialisation.
1368-
Let's take a simple example of variable hoisting,
1367+
1368+
Hoisting is JavaScript's default behavior where **variable and function declarations** are moved to the top of their scope before code execution. This means you can access certain variables and functions even before they are defined in the code.
13691369
1370-
```javascript
1371-
console.log(message); //output : undefined
1372-
var message = "The variable Has been hoisted";
1373-
```
13741370
1375-
The above code looks like as below to the interpreter,
1371+
Example of variable hoisting:
13761372
1377-
```javascript
1378-
var message;
1379-
console.log(message);
1380-
message = "The variable Has been hoisted";
1381-
```
1373+
```js
1374+
console.log(message); // Output: undefined
1375+
var message = "The variable has been hoisted";
1376+
```
1377+
1378+
```js
1379+
var message;
1380+
console.log(message); // undefined
1381+
message = "The variable has been hoisted";
1382+
```
13821383
1383-
In the same fashion, function declarations are hoisted too
1384+
Example of function hoisting:
13841385
1385-
```javascript
1386-
message("Good morning"); //Good morning
1386+
```js
1387+
message("Good morning"); // Output: Good morning
13871388

1388-
function message(name) {
1389-
console.log(name);
1390-
}
1391-
```
1389+
function message(name) {
1390+
console.log(name);
1391+
}
1392+
```
13921393
1393-
This hoisting makes functions to be safely used in code before they are declared.
1394+
Because of hoisting, functions can be used before they are declared.
13941395
13951396
**[⬆ Back to Top](#table-of-contents)**
13961397

0 commit comments

Comments
 (0)