You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: js codes.docx
+42-38Lines changed: 42 additions & 38 deletions
Original file line number
Diff line number
Diff line change
@@ -1839,7 +1839,8 @@ Hoisting:
1839
1839
4. Note: JavaScript only hoists declarations, not the initializations.
1840
1840
5. JavaScript allocates memory for all variables and functions defined in the program before execution.
1841
1841
6. Due to the concept of hoisting in JavaScript, we can call a function even before we define the function definition in our program's code.
1842
-
7. Variables defined with let and const are hoisted to the top of the block, but not initialized.
1842
+
7. Variables defined with let and const are hoisted to the top of the block, but not initialized.Let and const are also hoisted but we cant access them
1843
+
until they are assigned because they are in Temporal dead zone.To avoid Temporal deadzone we need to declare let and const to the top of our program!
1843
1844
1844
1845
Examples:
1845
1846
1. Hoisting Function: If i write below code then JS compiler auto move declaration first then call of a function.
@@ -1875,6 +1876,46 @@ console.log(x) //call //7
1875
1876
const x; //declaration
1876
1877
console.log(x) //call //Missing initializer in const declaration
greeting(); //function body will assign before executing //Hi greeting- as output post execution
1903
+
//greeting1(); //Uncaught TypeError: greeting1 is not a function because its treeting like a variable not a function, so rather then storing a function body it's storing undefined by default.
1904
+
//greeting2(); ////Uncaught TypeError: greeting1 is not a function because its treeting like a variable not a function, so rather then storing a function body it's storing undefined by default.
@@ -3041,44 +3082,7 @@ However, if you use the assignment operator for a reference value, it will not c
3041
3082
3042
3083
JS objects (as non-primitive data types) differ because they have reference values and those values are mutable. This means they share a memory address when shallow copied.
greeting(); //function body will assign before executing //Hi greeting- as output post execution
3066
-
//greeting1(); //Uncaught TypeError: greeting1 is not a function because its treeting like a variable not a function, so rather then storing a function body it's storing undefined by default.
3067
-
//greeting2(); ////Uncaught TypeError: greeting1 is not a function because its treeting like a variable not a function, so rather then storing a function body it's storing undefined by default.
0 commit comments