What is hoisting in JavaScript?

I-Hub Talent is recognized as one of the best Full Stack Java training institutes in Hyderabad, offering a comprehensive program designed to equip learners with the skills needed to excel in today’s competitive IT industry. The course covers everything from Core Java, Advanced Java (Servlets, JSP) to Spring Boot, Hibernate, REST APIs, and databases like MySQL, along with essential front-end technologies such as HTML, CSS, JavaScript, and frameworks like React.

What sets IHub Talent apart is its practical, project-based learning approach. Students gain real-world exposure through live projects and industry-driven case studies, ensuring they can confidently apply their skills in professional environments. The training is led by experienced mentors who bring years of industry expertise, guiding students step-by-step from basics to advanced concepts.

In addition to technical training, IHub Talent provides career-focused support including resume building, mock interviews, and dedicated placement assistance, enabling learners to secure job opportunities with top companies. The curriculum is regularly updated to match the latest industry trends, ensuring students remain competitive.

Whether you are a fresher looking to start your career or a professional aiming to upgrade your skills, IHub Talent offers the perfect environment to master Full Stack Java development and launch a successful IT career.

Hoisting in JavaScript is a default behavior of the JavaScript interpreter where variable and function declarations are moved (“hoisted”) to the top of their scope (global or function) before code execution.

This means you can use variables or functions before they are declared in the code, though the way it works depends on whether you use var, let, const, or a function declaration.

1. Variable Hoisting

  • Variables declared with var are hoisted but initialized as undefined.

  • Variables declared with let and const are hoisted too, but they remain in a Temporal Dead Zone (TDZ) until the declaration is reached. Accessing them before declaration throws a ReferenceError.

Example:

console.log(a); // undefined (due to var hoisting) var a = 10; console.log(b); // ReferenceError (TDZ) let b = 20;

2. Function Hoisting

  • Function Declarations are fully hoisted, meaning you can call them before their definition.

  • Function Expressions (using var, let, or const) are treated like variables, so only the variable name is hoisted, not the function body.

Example:

greet(); // Works because of hoisting function greet() { console.log("Hello!"); } sayHi(); // TypeError: sayHi is not a function var sayHi = function() { console.log("Hi!"); };

In short:

  • Declarations are hoisted, initializations are not.

  • var → hoisted as undefined.

  • let / const → hoisted but blocked in TDZ.

  • Function declarations → fully hoisted.

  • Function expressions → behave like variables.

Read More:


What are media queries?

Visit Our IHUB Talent Training Institute in Hyderabad        

Comments

Popular posts from this blog

What is @Entity annotation?

Explain merge conflict and how to resolve it.

What is Spring Framework?