0 votes
in JavaScript by
What is the difference between function and class declarations in javascript?

1 Answer

0 votes
by

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

Classes:

const user = new User(); // ReferenceError

class User {}

Constructor Function:

const user = new User(); // No error

function User() {}
...