JavaScript class
Example
Create a Car class, and then an object (myCar) based on the Car class:
class Car {
constructor(brand) {
this.carname = brand;
}
}
// Create a Car Object
myCar = new Car("Ford");
Description
A class is a type of object template.
The class statement initiates a JavaScript class.
Properties and methods are assigned in the constructor() method.
The constructor() method is called each time a class object is initialized.
See Also:
Notes
The syntax in a class must be written in "strict mode".
Unlike functions, class declarations are not hoisted (you must declare a class before you can use it).
Syntax
// class body
}
Related Pages
JavaScript Tutorial: JavaScript Classes
JavaScript Tutorial: JavaScript ES6 (EcmaScript 2015)
JavaScript Tutorial: JavaScript this
JavaScript Tutorial: JavaScript Strict Mode
Browser Support
class is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is supported in all browsers since June 2017:
| Chrome 51 |
Edge 15 |
Firefox 54 |
Safari 10 |
Opera 38 |
| May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |