javascriptclassfunction-expressionclass-expression

When we should use class expression in Javascript?


I have recently got to know that we do have class expressions too like function expressions in JS. I know some points about it(MDN) like:

  1. Class expressions may omit the class name ("binding identifier"), which is not possible with class statements.

  2. Class expressions allow you to redefine (re-declare) classes without throwing a SyntaxError.

I understand what it can help in, but where should be use it? What can be a classical example of using a class expression that can't be achieved with class statements or vice-versa?


Solution

  • There aren't that many, but any time you're using class as a right-hand value, you're automatically using a class expression (just as with function expressions).