Quickupdate

  • Home
  • Top Trending
    • Top Android Apps
    • Top Ios Apps
  • Featured
  • About Us
  • Contact us
  • Privacy Policy and Disclaimer

Friday, 15 October 2021

Hoisting In JavaScript

 Developers     October 15, 2021     No comments   

  1. Before saying anything checkout the below example.

    var x = 8;

    function getName(){
        console.log('My name in Rahul More');
    }
    getName();
    console.log(x)

  2. What do you think is the output of the above code?



    Yes, you guess that right. you will get output as you guessed it right.
  3. But here is a trick. what if we do something like this?

    getName();
    console.log(x)

    var x = 8;

    function getName(){
        console.log('My name in Rahul More');
    }


  4. Now can you guess what the will be the output?


    It's running Function getName but we got `undefined` for x
  5. But if we remove `x = 8` from we will get an error that `x is not defined`.

Undefined Vs Not Defined


  1. Accessing variables & functions before declaring is known as Hoisting in JS.
  2. the function is working as it is even if we moved that at TOP but Variable is not working properly.
  3. Even before executing the code memory got allocated for variables, functions for other things.



  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Popular Posts

  • How to upload the existing folder on GitHub Or GitLab?
    These are the steps to upload the existing folder on GitHub Or GitLab. Whenever you want to push your existing folder to git or GitHub you m...

Categories

  • FAANG (2)
  • Javascript (6)
  • Node (1)
  • Project Management (1)
  • React (9)
  • SQL (1)
  • Testing (1)

Blog Archive

  • January 2023 (1)
  • January 2022 (1)
  • November 2021 (3)
  • October 2021 (3)
  • August 2021 (1)
  • July 2021 (7)
  • June 2021 (12)
  • February 2021 (1)
  • January 2021 (1)
  • January 2020 (3)
  • August 2019 (3)