Reference for JavaScript (ECMAScript 2020)

The tables below show the syntactically highlighted topic for the language.


If you see any incorrect information, please help us improve! Feel free to either create an issue or use the link at the bottom of the language column to correct any information.

 

Defining Classes

Concept

JavaScript's Implementation

Normal class
class ClassName {
 // Class body containing variables and methods 
}
Abstract class
Not Implemented In This Language
Interface
Not Implemented In This Language
Read-only class
Not Implemented In This Language
Static class
Not Implemented In This Language
Inner class
Not Implemented In This Language
Packages
A package manager like NPM (https://www.npmjs.com/) or Deno (https://deno.land/) can be used to create and manage Javascript packages.
Class with a generic type
Not Implemented In This Language
 

Adding Private and Public Members

Concept

JavaScript's Implementation

Defining private variables
Not Implemented In This Language
Defining protected variables
Public and private are the only access modifiers available in Javascript.
Defining public variables
class ClassName {
 publicField = 0;
}
Field publicField is accessible at instance.publicField, where instance is the instance of the class ClassName.
Defining static variables
class ClassName {
 static staticField = 0;
}
Static field staticField is accessible at ClassName.staticField.
Defining private functions
Not Implemented In This Language
Defining protected functions
Not Implemented In This Language
Defining public functions
class ClassName {
 publicMethod() {
  // Method body
 }
}
Method publicMethod is accessible at instance.publicMethod(), where instance is the instance of the class ClassName.
Defining static functions
class ClassName {
 static staticMethod() {
  // Method body
 }
}
Static method staticMethod is accessible at ClassName.staticMethod().
Defining a getter for a property
Unknown
Defining a setter for a property
Unknown
 

Extending and Implementing Classes

Concept

JavaScript's Implementation

Class that inherits/extends another class
class ChildClassName extends ParentClassName {
 // Class body containing variables and methods 
}
class ParentClassName {
 // Class body containing variables and methods 
}
Class/Interface that inherits/extends another class/interface
Not Implemented In This Language
Calling a superclass function
super.methodName();
The super keyword is used to call a method of the parent class. To use it, the class must extend another class and the method must be defined in the parent class.
Overriding a superclass function
class ChildClassName extends ParentClassName {
 publicMethod() {
  // Method body
  // This overrides publicMethod() in the parent class
 }
}
 

Creating Objects and Polymorphism

Concept

JavaScript's Implementation

Instantiating a new object
const objectName = new ClassName();
Instantiating a polymorphic object
Not Implemented In This Language
 

Constructors and Destructor/Deconstructor

Concept

JavaScript's Implementation

Implementing a class constructor
class ClassName {
 constructor() {
  // Constructor body
 }
}
Implementing a class destructor/deconstructor
Not Implemented In This Language
 
 
Want to add or correct information for JavaScript?
or get the complete template. classes.json