Skip to content

Commit 8f1ce4e

Browse files
authored
Update js codes.docx
1 parent f02a6d6 commit 8f1ce4e

1 file changed

Lines changed: 42 additions & 38 deletions

File tree

‎js codes.docx‎

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,8 @@ Hoisting:
18391839
4. Note: JavaScript only hoists declarations, not the initializations.
18401840
5. JavaScript allocates memory for all variables and functions defined in the program before execution.
18411841
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!
18431844

18441845
Examples:
18451846
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
18751876
const x; //declaration
18761877
console.log(x) //call //Missing initializer in const declaration
18771878
x=7; //assignment
1879+
1880+
-------------------------------------------------------------------------------------
1881+
Hoisting:
1882+
var x = 1;
1883+
1884+
function greeting(){
1885+
console.log("Hi greeting");
1886+
}
1887+
1888+
var greeting1 = function (){
1889+
console.log("Hey greeting1");
1890+
}
1891+
1892+
var greeting2 = () =>{
1893+
console.log("Hello greeting2");
1894+
}
1895+
1896+
console.log(x); //1
1897+
greeting(); //Hi greeting
1898+
greeting1(); //Hey greeting1
1899+
greeting2(); //Hello greeting2
1900+
-----------------------------------------------------------------------
1901+
console.log(x); //undefined //1
1902+
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.
1905+
1906+
var x = 1;
1907+
1908+
function greeting(){
1909+
console.log("Hi greeting");
1910+
}
1911+
1912+
var greeting1 = function (){
1913+
console.log("Hey greeting1");
1914+
}
1915+
1916+
var greeting2 = () =>{
1917+
console.log("Hello greeting2");
1918+
}
18781919
================================================================================================================================================================================
18791920
Window and This:
18801921

@@ -3041,44 +3082,7 @@ However, if you use the assignment operator for a reference value, it will not c
30413082

30423083
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.
30433084
=========================================================================================================================================================================
3044-
Hoisting:
3045-
var x = 1;
3046-
3047-
function greeting(){
3048-
console.log("Hi greeting");
3049-
}
3050-
3051-
var greeting1 = function (){
3052-
console.log("Hey greeting1");
3053-
}
3054-
3055-
var greeting2 = () =>{
3056-
console.log("Hello greeting2");
3057-
}
3058-
3059-
console.log(x); //1
3060-
greeting(); //Hi greeting
3061-
greeting1(); //Hey greeting1
3062-
greeting2(); //Hello greeting2
3063-
-----------------------------------------------------------------------
3064-
console.log(x); //undefined //1
3065-
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.
3068-
3069-
var x = 1;
30703085

3071-
function greeting(){
3072-
console.log("Hi greeting");
3073-
}
3074-
3075-
var greeting1 = function (){
3076-
console.log("Hey greeting1");
3077-
}
3078-
3079-
var greeting2 = () =>{
3080-
console.log("Hello greeting2");
3081-
}
30823086
==========================================================================================================================================================================
30833087

30843088

0 commit comments

Comments
 (0)