They do largely the same thing. class
syntax was introduced in ES2015, and does a few things for you:
It builds in a check that the function was called as part of creating a new object, eliminating a whole class of errors that calling a constructor without new
allows.
It enables the use of super
in constructors and methods.
It's simpler, particularly if you do subclasses.
It's much simpler if you do subclasses of built-ins like Error
or Array
(you can do it without class
).
But you can do all of that without class
if you prefer to use the older syntax.
Of course, you can't use the new syntax on outdated browsers like IE without transpiling to the older syntax via tools like Babel.
(And obligatory note: Using class-like trappings on JavaScript's prototypical inheritance is a style choice, not a requirement. If you prefer, you can just use prototypical inheritance directly.)
You may also find this answer useful, comparing class
syntax with doing the same thing with function
syntax.