Google Chrome claims to support ES6 classes since version 42, but it gives Uncaught SyntaxError: Unexpected token class(…)
when i run the simple code from below in the console:
class Polygon {
constructor(height, width) {
this.name = 'Polygon';
this.height = height;
this.width = width;
}
Firefox also doesn't work. Microsoft Edge works just fine. Is this normal?
In Chrome, most of the ES6 features are hidden behind a flag called "Experimental JavaScript features". Visit chrome://flags/#enable-javascript-harmony , enable this flag, restart Chrome and you will get many new features.
ECMAScript 2015 (ES6) is Fully Supported on Google Chrome 53.
ES6 modules can be used without bundling out of the box on most modern browsers. The latest versions of Chrome, Firefox, Edge, Safari and mobile versions of them all support it out of the box. Other than Internet Explorer, most popular browsers can load ES6 modules on their own.
Note: ECMAScript 5 is Fully Supported on Google Chrome 56.
Are you in "use strict" mode?
ES6 classes solve this by providing JavaScript a clean, standardized syntax for classes. This new syntax is available in Chrome 42 for JavaScript written in strict mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With