JS Class Expression Last Updated : 15 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report JavaScript class is a type of function declared with a class keyword, that is used to implement an object-oriented paradigm. Constructors are used to initialize the attributes of a class.There are 2 ways to create a class in JavaScript.Class DeclarationClass ExpressionIn this article, we will discuss class expression to declare classes in JavaScript and how to use them.Class ExpressionThe class expression is another way of creating classes in JavaScript and they can be named or unnamed. If named, the class name is used internally, but not outside of the class.SyntaxUsing named class expression:const variable_name = new Class_name { // class body}Using unnamed class expression:const variable_name = class{ //class body}Example 1: Named class expression JavaScript const Website = class Geek { constructor(name) { this.name = name; } websiteName() { return this.name; } }; const x = new Website("GeeksforGeeks"); console.log(x.websiteName()); OutputGeeksforGeeks Example 2: Unnamed class expression. JavaScript const Website = class { constructor(name) { this.name = name; } returnName() { return this.name; } }; console.log(new Website("GeeksforGeeks").returnName()); OutputGeeksforGeeks Key Features of Class ExpressionsAnonymous Classes: Just like anonymous functions, you can define a class without giving it a name. This can be useful for situations where you don’t need to reference the class elsewhere.Assigning Classes to Variables: You can assign a class to a variable, which allows you to instantiate objects from that class later. This is a common way of using class expressions.Self-Invoking Class Expressions: A class can be invoked immediately after it is created, which allows for the creation of new objects right away.Supported BrowserChrome 42Edge 13Firefox 45Opera 29Safari 7 Comment U utkarsh_kumar Follow 2 Improve U utkarsh_kumar Follow 2 Improve Article Tags : JavaScript Web Technologies javascript-basics Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like