<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Sachin kumar</title>
    <description>The latest articles on Forem by Sachin kumar (@sachink07).</description>
    <link>https://forem.com/sachink07</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1056243%2Fe509ccc8-9b7b-45a1-b25e-a0c753b66560.png</url>
      <title>Forem: Sachin kumar</title>
      <link>https://forem.com/sachink07</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sachink07"/>
    <language>en</language>
    <item>
      <title>"Undefined" in javascript: Amazing Cases.</title>
      <dc:creator>Sachin kumar</dc:creator>
      <pubDate>Tue, 18 Apr 2023 16:49:52 +0000</pubDate>
      <link>https://forem.com/sachink07/undefined-in-javascript-amazing-cases-4gk9</link>
      <guid>https://forem.com/sachink07/undefined-in-javascript-amazing-cases-4gk9</guid>
      <description>&lt;p&gt;📗 &lt;strong&gt;𝐓𝐡𝐞 𝐂𝐮𝐫𝐢𝐨𝐮𝐬 𝐂𝐚𝐬𝐞 𝐨𝐟 "𝐔𝐧𝐝𝐞𝐟𝐢𝐧𝐞𝐝" 𝐢𝐧 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;👉 In JavaScript, "undefined" is a primitive data type that represents a value that is not assigned to a variable or a property. "undefined" is a property of the global object. That is, it is a variable in global scope.&lt;/p&gt;

&lt;p&gt;JavaScript uses the undefined value in the following situations.&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;1) 𝐀𝐜𝐜𝐞𝐬𝐬𝐢𝐧𝐠 𝐚𝐧 𝐮𝐧𝐢𝐧𝐢𝐭𝐢𝐚𝐥𝐢𝐳𝐞𝐝 𝐯𝐚𝐫𝐢𝐚𝐛𝐥𝐞&lt;/strong&gt;&lt;br&gt;
When we declare a variable and don’t initialize it to a value, the variable will have a value of ''undefined''.&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x;
console.log(x); // Output: undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ &lt;strong&gt;2) 𝐀𝐜𝐜𝐞𝐬𝐬𝐢𝐧𝐠 𝐚 𝐧𝐨𝐧-𝐞𝐱𝐢𝐬𝐭𝐢𝐧𝐠 𝐩𝐫𝐨𝐩𝐞𝐫𝐭𝐲 𝐨𝐟 𝐚𝐧 𝐨𝐛𝐣𝐞𝐜𝐭&lt;/strong&gt;&lt;br&gt;
If we access a non-existing property of an object, we’ll get undefined.&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person = {
name: "Sachin",
};
console.log(person.age); // undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the person object has one property "name". Accessing the "age" property that doesn’t exist on the "person" object returns undefined.&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;3) 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 𝐩𝐚𝐫𝐚𝐦𝐞𝐭𝐞𝐫𝐬&lt;/strong&gt;&lt;br&gt;
when we call the function and don’t pass all the arguments, the parameters inside the function become undefined.&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const calculation = (a, b ) =&amp;gt; {
  return b === 7 ? ${ a } : ${ a} ${ b };
}
calculation(3); // 3 undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ &lt;strong&gt;4) 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧𝐬 𝐫𝐞𝐭𝐮𝐫𝐧 𝐚 𝐯𝐚𝐥𝐮𝐞&lt;/strong&gt;&lt;br&gt;
A function that doesn’t have a return statement implicitly returns undefined.&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function myFunc() {
// Do something but don't return a value
}
console.log(myFunc()); // Output: undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ &lt;strong&gt;5) 𝐀𝐜𝐜𝐞𝐬𝐬𝐢𝐧𝐠 𝐨𝐮𝐭-𝐨𝐟-𝐛𝐨𝐮𝐧𝐝𝐬 𝐚𝐫𝐫𝐚𝐲 𝐞𝐥𝐞𝐦𝐞𝐧𝐭𝐬&lt;/strong&gt;&lt;br&gt;
When we access an array element that is out-of-bounds, we'll get the undefined value.&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const colors = ['red', 'green', 'blue'];
console.log(colors[3]); // undefined`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 &lt;strong&gt;𝐒𝐮𝐦𝐦𝐚𝐫𝐲&lt;/strong&gt;&lt;br&gt;
✅ The undefined is a primitive type that has a single value undefined.&lt;br&gt;
✅ Accessing an uninitialized variable returns undefined.&lt;br&gt;
✅ Accessing a non-existing property of an object returns undefined.&lt;br&gt;
✅ Accessing an out-of-bounds array element returns undefined.&lt;br&gt;
✅ A function without a return statement or with a return statement but without an expression returns undefined.&lt;/p&gt;

&lt;p&gt;That's all for today 🙂&lt;/p&gt;

&lt;p&gt;Thanks for reading it 😊. I hope it was insightful and that we got to learn something new today. If you liked the post, please post likes 👍 and share 🤝 it in your circles. Share your feedback and comment away.&lt;/p&gt;

&lt;p&gt;Let's connect on &lt;a href="https://www.linkedin.com/in/sachin-kumar007/"&gt;LinkedIn&lt;/a&gt;. I'd love to connect :)&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Hoisting in JavaScript ( Part -2 ) Practise Question.</title>
      <dc:creator>Sachin kumar</dc:creator>
      <pubDate>Sun, 09 Apr 2023 07:10:34 +0000</pubDate>
      <link>https://forem.com/sachink07/hoisting-in-javascript-part-2-practise-question-608</link>
      <guid>https://forem.com/sachink07/hoisting-in-javascript-part-2-practise-question-608</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CfBqJOxA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y9rkjlgzshvypwigw19e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CfBqJOxA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y9rkjlgzshvypwigw19e.png" alt="Hoisting In javascript, where variables and functions can be accessed even before they are initialised." width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📗 What is Hoisting in JavaScript?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In JavaScript, hoisting is a behavior where variables and functions can be accessed even before they are initialised. This is because, during the creation phase of the JavaScript execution context, all the variables are allocated memory with an initial value of undefined, and the entire function code is also placed in the execution context.&lt;/p&gt;

&lt;p&gt;When we try to access a variable during the code execution phase, it will contain the variable with an undefined value. Similarly, when we invoke a function, the whole code of the function is present, and it will work as expected.&lt;/p&gt;

&lt;p&gt;Even let and const variables are hoisted, but they are placed in the Temporal Dead Zone until they are initialized. This means that an error is thrown when we try to access them before they are initialized.&lt;/p&gt;

&lt;p&gt;In summary, hoisting is a feature of JavaScript that allows variables and functions to be accessed before they are declared, but it's important to note that let and const variables are hoisted differently, and accessing them before initialization can result in an error.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question 1.&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(y);
y = 1;
--------------------------

console.log(y);
var y = 2;
-------------------------

y = 3;
console.log(y);
var y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;// Output: 🤔&lt;br&gt;
// ReferenceError: y is not defined&lt;br&gt;
// undefined&lt;br&gt;
// 3&lt;/p&gt;

&lt;p&gt;Explanation: Behind the scene, JavaScript interprets the above code as:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(y); // ReferenceError: y is not defined
y = 1;
-------------------

var y = undefined;
console.log(y); // undefined
y = 2;
-------------------

var y = undefined;
y = 3;
console.log(y); // 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Question 2:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var a = 1;
console.log(a);

var a = 2;
console.log(a);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;// Output: 🤔&lt;br&gt;
// 1&lt;br&gt;
// 2&lt;/p&gt;

&lt;p&gt;Explanation: Behind the scene, JavaScript interprets above code as:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var a = undefined;
a = 1;
console.log(a); // 1

a = 2;
console.log(a); // 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Question 3:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var z = 1;
let z;
console.log(z);

-----------------

console.log(z);
let z = 1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;// Output: 🤔 &lt;br&gt;
// Identifier ‘z’ has already been declared Cannot access ‘z’ before  initialization&lt;/p&gt;

&lt;p&gt;Explanation: Behind the scene, JavaScript interprets above code as:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var z = 1;
let z; //   SyntaxError: Identifier ‘z’ has already been declared
console.log(z);

-----------------

let z;
console.log(z); //  ReferenceError: Cannot access ‘z’ before
                //  initialization
z = 1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Question 4:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function hoistExample() {
    var a;
    console.log("Before: ", a);
    a = 10;
    console.log("After: ", a);
}
hoistExample();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;// Output: 🤔&lt;br&gt;
// Before: Undefined&lt;br&gt;
// After: 10&lt;/p&gt;

&lt;p&gt;Explanation: Behind the scene, JavaScript interprets above code as:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function hoistingExample() {
    var a = undefined;
    console.log("Before: ", a);  // undefined
    a = 10;
    console.log("After: ", a); // 10
}
hoistingExample();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Question 5:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function hoistingExample() {
    console.log("Value of a in local scope: ", a);
}
console.log("Value of a in global scope: ", a);
var a = 1;
hoistingExample();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;// Output: 🤔&lt;br&gt;
// Value of an in global scope: Undefined Value of an in local scope: 1&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;When the code runs, it first declares a variable a in the global scope using the var keyword, but it does not assign a value to it yet. Then it calls the hoistingExample() function.&lt;/p&gt;

&lt;p&gt;Inside the function, it tries to log the value of an in the local scope, but at this point, a is undefined because it has not been assigned a value yet.&lt;/p&gt;

&lt;p&gt;After the function declaration, the code logs the value of an in the global scope, which is still undefined at this point.&lt;/p&gt;

&lt;p&gt;Finally, the code assigns the value of 1 to the variable.&lt;/p&gt;

&lt;p&gt;So when the hoistingExample() function is called, it logs undefined for the value of an in the local scope, but after the function is called, the value of an in the global scope has been updated to 1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question 6:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function hoistingExample() {
    a = 1;
}
hoistingExample();
console.log(a);

----------------------------

function hoistingExample() {
    var a = 1;
}
hoistingExample();
console.log(a);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;// Output: 🤔 &lt;br&gt;
// 1 ReferenceError: a is not defined&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;In the first code snippet, the variable a is not declared with the var, let, or const keyword. Therefore, it will be automatically declared in the global scope and assigned the value of 1 inside the hoistingExample() function. When console.log(a) is executed outside of the function, it will output 1 since a is in the global scope and has not been reassigned.&lt;/p&gt;

&lt;p&gt;In the second code snippet, the variable a is declared using the var keyword inside the hoistingExample() function. This means that a is only accessible within the function's local scope and cannot be accessed outside of it. Therefore, when console.log(a) is executed outside of the function, it will result in a reference error since a is undefined in the global scope.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question 7:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function a(){
    console.log("1")
}
a();

function a(){
    console.log("2")
}
a();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;// Output: 🤔&lt;br&gt;
// 2 &lt;br&gt;
// 2&lt;/p&gt;

&lt;p&gt;Explanation: Behind the scene, JavaScript interprets above code as:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function a(){
    console.log("1")
}
function a(){
    console.log("2")
}
a(); // 2
a(); // 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;When two function declarations of the same name are defined in the same scope, the second one will overwrite the first. In this case, the second a() declaration outputs 2 to the console, so when a() is called after the second declaration, it will execute the updated code block and output 2.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question 8:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var test = 1;
function functionHoisting() {
    test = 10;
    return;
    function test() {}
}
functionHoisting();
console.log(test);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;// Output: 🤔&lt;br&gt;
// 1&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;The reason for this output is that the function declaration of test() inside the functionHoisting() function has no effect due to the return statement that immediately follows it.&lt;/p&gt;

&lt;p&gt;When functionHoisting() is called, it sets the value of the global variable test to 10. However, the function declaration of test() inside the function does not change the value of the global test variable. This is because the function declaration is hoisted to the top of the function scope, but it is never actually called or executed.&lt;/p&gt;

&lt;p&gt;Therefore, when console.log(test) is executed outside of the function, it outputs the original value of 1 that was set at the beginning of the program, rather than the updated value of 10 that was set inside functionHoisting().&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question 9:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(a());
function a() {
    var b = function () {
        return 3;
    };
    return b();
    var b = function () {
        return 8;
    };
}

-------------------------------------------------------------

console.log(a());
function a() {
    var b = function () {
        return 3;
    };
    return b();
    var b = function () {
        return 8;
    };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;// Output: 🤔 &lt;br&gt;
// 3 &lt;br&gt;
// 8&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;In the first snippet, the function defines a variable b with a function expression that returns 3. This is followed by a return statement that immediately invokes the b function and returns its result.&lt;/p&gt;

&lt;p&gt;The second function expression that returns 8 is never executed because it is defined after the return statement. So, the b function that is returned and invoked is the one that returns 3.&lt;/p&gt;

&lt;p&gt;Therefore, console.log(a()) will log 3 to the console.&lt;/p&gt;

&lt;p&gt;In the second snippet, When a() is called, it returns the value of the function b(). However, the b() function that is returned is the second b() function, which returns the value 8. This is because the second b() function is defined after the first b() function, so it "overrides" the first b() function.&lt;/p&gt;

&lt;p&gt;Therefore, when a() is called, it returns the value 8&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question 10:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var temp= 'hi';
function display(){
     console.log(temp);
     var temp = 'bye';
};
display();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;// Output:&lt;br&gt;
// undefined&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;Within the display() function, there is a variable named temp that is declared using the var keyword. When the console.log(temp) statement is executed, the JavaScript interpreter looks for the value of temp within the local scope of the display() function.&lt;/p&gt;

&lt;p&gt;However, since the temp variable is declared using var, it is hoisted to the top of the function scope. This means that the variable is technically declared before it is assigned a value. So, when console.log(temp) is called, the temp variable exists within the local scope of display(), but it has not yet been assigned a value.&lt;/p&gt;

&lt;p&gt;As a result, the value of temp at this point is undefined.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks for reading it 😊. I hope it was insightful and that we got to learn something new today. If you liked the post, please post likes and share it in your circles. Share your feedback and comment away.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's connect on &lt;a href="https://www.linkedin.com/in/sachin-kumar007/"&gt;LinkedIn&lt;/a&gt;. I'd love to connect :)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Hoisting In Javascript ( Part - 1 ):</title>
      <dc:creator>Sachin kumar</dc:creator>
      <pubDate>Sat, 01 Apr 2023 12:57:54 +0000</pubDate>
      <link>https://forem.com/sachink07/hoisting-in-javascript-part-1--4bne</link>
      <guid>https://forem.com/sachink07/hoisting-in-javascript-part-1--4bne</guid>
      <description>&lt;p&gt;&lt;strong&gt;Hoisting&lt;/strong&gt; is a behavior in JavaScript where variable and function declarations are moved to the top of their respective scopes (global or local) before the code is executed. This means that even if a variable or function is declared later in the code, it can be used before its actual declaration.&lt;/p&gt;

&lt;p&gt;There are a few important concepts to understand to master hoisting in JavaScript:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Variable Hoisting&lt;/strong&gt;: In JavaScript, variable declarations are moved to the top of their scope during hoisting, but their assignments are not. This means that if you declare a variable using &lt;strong&gt;"var"&lt;/strong&gt;, it will exist in memory with a default value of &lt;strong&gt;"undefined"&lt;/strong&gt; before its actual declaration in the code.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// For example: 

console.log(myVar);  // Output: undefined
var myVar = 5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code will log &lt;strong&gt;"undefined"&lt;/strong&gt; to the console, because &lt;strong&gt;"myVar"&lt;/strong&gt; exists in memory with a default value of "undefined" before its declaration on the second line.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Function Hoisting:&lt;/strong&gt; Function declarations are also hoisted in JavaScript, meaning they can be used before their actual declaration in the code. This is because function declarations are moved to the top of their scope during hoisting, including their entire code block.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// For example:

myFunc();  // 𝐎𝐮𝐭𝐩𝐮𝐭: "Hello World!"
function myFunc() { 
    console.log("Hello World!"); 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code will log &lt;strong&gt;"Hello World!"&lt;/strong&gt; to the console, even though "𝐦𝐲𝐅𝐮𝐧𝐜" is called before its actual declaration in the code.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Block Scoping:&lt;/strong&gt; In modern JavaScript, &lt;strong&gt;"let"&lt;/strong&gt; and &lt;strong&gt;"const"&lt;/strong&gt; keywords are used for block-scoped variable declaration. Unlike &lt;strong&gt;"var"&lt;/strong&gt;, block-scoped variables are not hoisted to the top of their scope, and cannot be accessed before their actual declaration in the code.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// For example:

console.log(myVar); // Output: ReferenceError: Cannot access 'myVar' before initialization
let myVar = 5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you try to access the value of a variable declared with let or const before it has been initialized, JavaScript will throw a &lt;strong&gt;ReferenceError&lt;/strong&gt; with the message &lt;strong&gt;"Cannot access 'myVar' before initialization"&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In summary, hoisting is a behavior in JavaScript where variable and function declarations are moved to the top of their respective scopes during the code execution. Understanding &lt;strong&gt;variable hoisting, function hoisting and block scoping hoisting&lt;/strong&gt; is important for mastering hoisting in JavaScript.&lt;/p&gt;

&lt;p&gt;In this post, we have learned what is hoisting in Js. In the next post, we will practice some questions for a better grip on Hoisting, so stay tuned 🙂.&lt;/p&gt;

&lt;p&gt;Thanks for reading it😊. I hope it was insightful and you got to learn something new today. If you liked the article, please post likes and share it in your circles. Share your feedback and comment away.&lt;/p&gt;

&lt;p&gt;Let's connect on &lt;a href="https://www.linkedin.com/in/sachin-kumar007/"&gt;LinkedIn&lt;/a&gt;. I'd love to connect :)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
