Skip to content

Commit da92bcb

Browse files
Merge pull request #6 from HariAcidReign/restyled/pull-5
Restyle Definition of Undefined is Missing
2 parents 4ba4b9a + e97d23d commit da92bcb

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

Diff for: Notes/3-Hoisting.md

+33-28
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ console.log(x);
1616

1717
Output:
1818

19-
> Namaste JavaScript
19+
> Namaste JavaScript
2020
21-
> 7
21+
> 7
2222
2323
```
2424
// code example 2
2525
26-
getName(); // in most languages, both lines which are above their declaration will give error. Not in JS though.
27-
console.log(x);
26+
getName(); // in most languages, both lines which are above their declaration will give error. Not in JS though.
27+
console.log(x);
2828
2929
var x = 7;
3030
@@ -34,10 +34,11 @@ function getName(){
3434
3535
```
3636

37-
Output:
38-
> Namaste JavaScript
37+
Output:
38+
39+
> Namaste JavaScript
3940
40-
> undefined
41+
> undefined
4142
4243
```
4344
// code example 3
@@ -53,14 +54,18 @@ function getName(){
5354

5455
Output:
5556

56-
> Namaste JavaScript
57+
> Namaste JavaScript
5758
58-
> Error: x is not defined // note that not defined here and "undefined" in sample 2 are totally different.
59+
> Error: x is not defined // note that not defined here and "undefined" in
60+
> sample 2 are totally different.
5961
60-
- Not defined: We have not initialised the value for variable anywhere in the entire code and in memory space.
61-
- Undefined:
62+
- Not defined: We have not initialised the value for variable anywhere in the
63+
entire code and in memory space.
64+
- Undefined: It is a placeholder that is assigned to a variable by the
65+
Javascript Engine until the variable is assigned with some other value.
6266

63-
__Hoisting__ is a concept which enables us to extract values of variables and functions even before initialising/assigning value without getting *error*
67+
**Hoisting** is a concept which enables us to extract values of variables and
68+
functions even before initialising/assigning value without getting _error_
6469

6570
```
6671
@@ -78,9 +83,10 @@ console.log(getName)
7883
Output:
7984

8085
> f getName(){
86+
8187
console.log("Namaste JavaScript);
82-
}
8388

89+
}
8490

8591
```
8692
@@ -99,13 +105,16 @@ function getName(){
99105
```
100106

101107
Output:
102-
> Namaste JavaScript
103108

104-
> undefined
109+
> Namaste JavaScript
110+
111+
> undefined
112+
113+
> f getName(){
105114
106-
> f getName(){
107115
console.log("Namaste JavaScript);
108-
}
116+
117+
}
109118

110119
```
111120
// code example 6
@@ -116,26 +125,22 @@ var getName = function () {
116125
console.log("Namaste JavaScript");
117126
}
118127
119-
var getName = () => { // use fat arrow function
128+
var getName = () => { // use fat arrow function
120129
console.log("Namaste JavaScript");
121130
}
122131
123132
```
124133

125134
Output:
126135

127-
> undefined //it is because they behave as variable and not function.
136+
> undefined //it is because they behave as variable and not function.
128137
129138
---
130139

131-
__REASON OF WEIRDNESS__
132-
133-
* The answer lies in the Global Exection Context. In the memory phase, the variables will be initialized as *undefined* and functions will get the whole function code in their memory.
134-
135-
* This is the reason why we are getting these outputs.
136-
137-
138-
139-
140+
**REASON OF WEIRDNESS**
140141

142+
- The answer lies in the Global Exection Context. In the memory phase, the
143+
variables will be initialized as _undefined_ and functions will get the whole
144+
function code in their memory.
141145

146+
- This is the reason why we are getting these outputs.

0 commit comments

Comments
 (0)