Alex Rivera | Logout

Does JavaScript have classes?

Asked 2010-05-02T08:37:25.800
87

A friend and I had an argument last week. He stated there were no such things as classes in JavaScript.

  • I said there was, as you can say var object = new Object().
  • He said "as there is no word class used, it's not a class".

Who is right?


‍♂️ NOTE

This question was first asked before the introduction of class syntax in ECMAScript 6th Edition (2015). Even then, as remarked above, the presence of this syntax alone need not necessarily settle the question.

Edit
Report

2 Answers

125

Technically, the statement "JavaScript has no classes" is correct.

Although JavaScript is object-oriented language, it isn't a class-based language—it's a prototype-based language. There are differences between these two approaches, but since it is possible to use JavaScript like a class-based language, many people (including myself) often simply refer to the constructor functions as "classes".

answered 2010-05-02T08:46:37.887
7

In Javascript pretty much everything is an object (objects can inherit from other objects). It does not have classes in the classical sense.

Although you can reproduce most of the functionality of traditional class definition / instantiation by function prototyping.

answered 2010-05-02T08:43:52.020

Your Answer