coderef

ClassesBaseline · Widely available

Classes are an object-oriented syntax for JavaScript prototypes.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Mar 8, 2016. Widely available since Sep 8, 2018.

Browser support

DesktopChrome
1–41Not supported
42+Supportedsince Apr 14, 2015
Current: 155
Edge
12–12Not supported
13+Supportedsince Nov 12, 2015
Current: 154
Firefox
1–44Not supported
45+Supportedsince Mar 8, 2016
Current: 157
Safari
1–8Not supported
9+Supportedsince Sep 30, 2015
Current: 27
MobileChrome Android
18–41Not supported
42+Supportedsince Apr 15, 2015
Current: 155
Firefox Android
4–44Not supported
45+Supportedsince Mar 8, 2016
Current: 157
Safari iOS
1–8Not supported
9+Supportedsince Sep 16, 2015
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: Classes.

Feature detection

JS · check before using
// Syntax can't be tested with an if-statement — an unsupported
// browser fails to parse the whole script. Either transpile for older
// targets (e.g. Babel/TypeScript/esbuild), or probe in isolation:
let supported = true;
try {
  new Function("/* code that uses the syntax */");
} catch {
  supported = false;
}

This is a language syntax feature.

Sub-features

Support for each part of the feature (14). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
javascript.classes421345942459
javascript.classes.constructor421345942459
javascript.classes.extends421345942459
javascript.classes.private_class_fields74799014.1749014.5
javascript.classes.private_class_fields_in91919015919015
javascript.classes.private_class_methods84849015849015
javascript.classes.public_class_fields72796916727916
javascript.classes.static421345942459
javascript.classes.static.class_fields72797514.1727914.5
javascript.classes.static.initialization_blocks94949316.4949316.4
class421345742457
new_target46134111464111
super421345742457
class42134510.1424510.3