Let's start with a code example,
The above way of writing a method with a
function keyword is called a function declaration.
foo() is available before its declaration.
You can write a function in another way and its called function expression. With function expression, you declare an anonymous function and assign it to a variable. Let's see that with a code example.
The data type of an ES6 class is a Function. So, classes behave the same as function when it comes to hoisting. Class declarations are hoisted and Class expressions are not.
There is one extra rule with class declarations, you have to declare a class before you can use it. Let's take a look,
Same as function expression, class expressions are not hoisted.
- Function and ES6 Class declarations are hoisted.
- Function and ES6 Class expressions are not hoisted.
consthoist the same way as