Skip to content

Commit 6f28416

Browse files
authored
Update js codes.docx
1 parent 25c5d62 commit 6f28416

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

‎js codes.docx‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3040,7 +3040,46 @@ Output: 1
30403040
However, if you use the assignment operator for a reference value, it will not copy the value. Instead, both variables will reference the same object in the memory:
30413041

30423042
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.
3043-
3043+
=========================================================================================================================================================================
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
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;
3070+
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+
}
3082+
==========================================================================================================================================================================
30443083

30453084

30463085

0 commit comments

Comments
 (0)