Hoisting - MDN Web Docs Glossary: Definitions of Web-related terms | MDN
JavaScript Hoisting refers to the process whereby the interpreter appears to move the declaration of functions, variables or classes to the top of their Variable Scope, prior to execution of the code.
An important difference between function declarations and class declarations is that while functions can be called in code that appears before they are defined, classes must be defined before they can be constructed. Code like the following will throw a ReferenceError
:
Function hoisting
One of the advantages of hoisting is that it lets you use a function before you declare it in your code.
Exceptions
Function expressions and class expressions are not hoisted.