JS Coding Questions Logo
JS Coding Questions
#409💼 Interview💻 Code

What is the difference between function and class declarations

Advertisement

728x90

The main difference between function declarations and class declarations is hoisting. The function declarations are hoisted but not class declarations.

Classes:

javascript
1const user = new User(); // ReferenceError
2
3class User {}

Constructor Function:

javascript
1const user = new User(); // No error
2
3function User() {}

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 66

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
409of476
What is the difference between function and class declarations | JSCodingQuestions.com