From cdf2d7eb521103a49751af9996a11d87a1d59efe Mon Sep 17 00:00:00 2001 From: Akash Date: Mon, 11 Oct 2021 19:38:28 +0530 Subject: [PATCH 1/2] Definition of Undefined is Missing Added In the Missing definition of the Undefined variable in Javascript on Line 61. --- Notes/3-Hoisting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/3-Hoisting.md b/Notes/3-Hoisting.md index c42b0b9..2ad02a3 100644 --- a/Notes/3-Hoisting.md +++ b/Notes/3-Hoisting.md @@ -58,7 +58,7 @@ Output: > Error: x is not defined // note that not defined here and "undefined" in sample 2 are totally different. - Not defined: We have not initialised the value for variable anywhere in the entire code and in memory space. -- Undefined: +- Undefined: It is a placeholder that is assigned to a variable by the Javascript Engine until the variable is assigned with some other value. __Hoisting__ is a concept which enables us to extract values of variables and functions even before initialising/assigning value without getting *error* From e97d23d08d0614c9dc893fdc91274101f534c5f8 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 11 Oct 2021 14:08:42 +0000 Subject: [PATCH 2/2] Restyled by prettier-markdown --- Notes/3-Hoisting.md | 61 ++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/Notes/3-Hoisting.md b/Notes/3-Hoisting.md index 2ad02a3..5529086 100644 --- a/Notes/3-Hoisting.md +++ b/Notes/3-Hoisting.md @@ -16,15 +16,15 @@ console.log(x); Output: -> Namaste JavaScript +> Namaste JavaScript -> 7 +> 7 ``` // code example 2 -getName(); // in most languages, both lines which are above their declaration will give error. Not in JS though. -console.log(x); +getName(); // in most languages, both lines which are above their declaration will give error. Not in JS though. +console.log(x); var x = 7; @@ -34,10 +34,11 @@ function getName(){ ``` - Output: -> Namaste JavaScript +Output: + +> Namaste JavaScript -> undefined +> undefined ``` // code example 3 @@ -53,14 +54,18 @@ function getName(){ Output: -> Namaste JavaScript +> Namaste JavaScript -> Error: x is not defined // note that not defined here and "undefined" in sample 2 are totally different. +> Error: x is not defined // note that not defined here and "undefined" in +> sample 2 are totally different. -- Not defined: We have not initialised the value for variable anywhere in the entire code and in memory space. -- Undefined: It is a placeholder that is assigned to a variable by the Javascript Engine until the variable is assigned with some other value. +- Not defined: We have not initialised the value for variable anywhere in the + entire code and in memory space. +- Undefined: It is a placeholder that is assigned to a variable by the + Javascript Engine until the variable is assigned with some other value. -__Hoisting__ is a concept which enables us to extract values of variables and functions even before initialising/assigning value without getting *error* +**Hoisting** is a concept which enables us to extract values of variables and +functions even before initialising/assigning value without getting _error_ ``` @@ -78,9 +83,10 @@ console.log(getName) Output: > f getName(){ + console.log("Namaste JavaScript); - } +} ``` @@ -99,13 +105,16 @@ function getName(){ ``` Output: -> Namaste JavaScript -> undefined +> Namaste JavaScript + +> undefined + +> f getName(){ -> f getName(){ console.log("Namaste JavaScript); - } + +} ``` // code example 6 @@ -116,7 +125,7 @@ var getName = function () { console.log("Namaste JavaScript"); } -var getName = () => { // use fat arrow function +var getName = () => { // use fat arrow function console.log("Namaste JavaScript"); } @@ -124,18 +133,14 @@ var getName = () => { // use fat arrow function Output: -> undefined //it is because they behave as variable and not function. +> undefined //it is because they behave as variable and not function. --- -__REASON OF WEIRDNESS__ - -* 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. - -* This is the reason why we are getting these outputs. - - - - +**REASON OF WEIRDNESS** +- 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. +- This is the reason why we are getting these outputs.