Hoisting in JavaScript
🌐 Tech Enthusiast | Curious Learner | Knowledge Sharer Hello! Currently, I am pursuing a Master's degree in Computer Applications (MCA) from the Heritage Institute of Technology. Since the world of technology is dynamic, I posted some pieces based on my experiences and what is trending right now. My blog is an informative space where it is possible to create a community, learn together, and grow. Considering my interests in Web Development, Artificial Intelligence, and DevOps, I am always ready to explore new technologies, share knowledge with others, and step up the ladder of success simultaneously. Join me as I navigate this exciting journey of growth and innovation! 🚀
This is my second blog on the topic "Hoisting," which is a very interesting phenomenon in JS.
JavaScript Hoisting refers to the process where the interpreter appears to move the declaration of functions, variables, classes, or imports to the top of their scope, prior to the execution of the code.
But what does it mean?
lets find it with an example

The above example is a simple JavaScript code where we initialize a variable "x" and a function a(), and later call them, getting the obvious answer.
But what If we do this?

Here we call the function and the variable before even declaring them. In that case, we get the answer "Hello world" and "undefined." The reason behind this answer is "Hoisting."
So, in simple words, "Hoisting" is a phenomenon in JS where we can declare a function or a variable even before initializing them, and we can access them without any error.
But wait where this "undefined" comes from ?
In JavaScript when we run a code JavaScript create a Global Execution Context and It creates in two phases (1) Memory (2) Code. So in the above example when we run this code a memory space is allocated for the variable "x" and allocate the value as "undefined" by default . Similarly, function declarations are also hoisted to the top of their scope, allowing them to be invoked before their actual declaration in the code.
