A class expression has a similar syntax to a class declaration (statement). As with class
statements, the body of a class
expression is executed in strict mode.
There are several differences between class expressions and class statements, however:
- Class expressions may omit the class name ("binding identifier"), which is not possible with class statements.
- Class expressions allow you to redefine (re-declare) classes without throwing a
SyntaxError
. This is not the case with class statements.
The constructor
method is optional. Classes generated with class expressions will always respond to typeof
with the value "function
".
'use strict';
let Foo = class {};
Foo = class {};
typeof Foo;
typeof class {};
Foo instanceof Object;
Foo instanceof Function;
class Foo {}