??What is Hoisting in JavaScript | Hoisting Functions, Variables and Classes
Sonu Kumar
Frontend Engineer @ Wellness Extract | React.js & Next.js Expert | Vue.js | Angular | Node.js | React Router & Redux | React Query & GraphQL | PWA & SaaS Developer | 3+ Years Crafting Modern, Scalable Products
Hoisting is a fundamental concept in JavaScript where function, variable, or class declarations are moved to the top of their scope during the compilation phase (before the code execution). This behavior allows you to use functions or variables before they are declared in the code.
However, only declarations are hoisted, not initializations or assignments. Let’s dive deep into how hoisting works for functions, variables, and classes.
Function Hoisting
In JavaScript, function declarations are fully hoisted. This means you can call a function even before it’s declared in the code.
Key Points:
Variable Hoisting
Variable declarations using var, let, and const behave differently when hoisted:
Class Hoisting
Classes in JavaScript are also hoisted, but they are not initialized. Accessing a class before its declaration will result in a ReferenceError.
Got questions or examples where hoisting surprised you? Let’s discuss below! ?? #JavaScript #CodingTips #WebDevelopment
Frontend Web Developer || React || JavaScript ||Tailwind CSS || Responsive Web design || CSS || HTML || C || C++ || Python || Data Science
3 个月Useful tips