Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Alberto Medrano
Alberto Medrano
12,916 Points

Is JavaScript (entirely) an Object-Oriented Language?

It seems to me that JavaScript does not fully support Object-Oriented Programming, well, as far as I read in an article, that programming languages are more object-oriented than others.

Steven Parker
Steven Parker
231,210 Points

:point_right: This MDN page sums it up nicely:

"Object-oriented to the core, JavaScript features powerful, flexible OOP capabilities."

5 Answers

Ioannis Leontiadis
Ioannis Leontiadis
9,828 Points

Hello amedrano,

the most satisfying answer to this question for me is that JavaScript is heavily object oriented. As with all definitions and implementations there is always space for some argument. I found this question on stack overflow to be quite informing.

Also, lets quote wikipedia:

"Many of the most widely used programming languages are multi-paradigm programming languages that support object-oriented programming to a greater or lesser degree, typically in combination with imperative, procedural programming."

JavaScript supports Object-Oriented Programming( OOP ) and there are not many stories where it failed to implement an Object-Oriented Design( OOD ), so..

Hope that helped!

Sorry, while JavaScript has object-oriented programming (added in ES5), JavaScript is still not considered an object-oriented language.

Ioannis Leontiadis
Ioannis Leontiadis
9,828 Points

What do you mean by Object-Oriented language ?

I meant by a language that supports actual Objects.

JavaScript isn't a object-oriented language, so there's no classes in JavaScript.

Most other languages (PHP, Python, Ruby, Swift, Objective-C, C#, Java, etc.) include a thing called classes.

Since you are used to JavaScript, you can think of classes as objects.

Classes are like a blueprint for things, like for instance a car.

Most classes have methods and attributes.

  • Methods are actions, like for instance a car would probably have a "drive" method, and a "stop" method.
  • Attributes are values attached to the class (blueprint), like the car class might have a "color" attribute and a "top-speed" attribute.

Just keep in mind, JavaScript is not object-oriented and is a prototype-based language.

Tagging Steven Parker

Ioannis Leontiadis
Ioannis Leontiadis
9,828 Points

Thank you for pointing out, but because JavaScript's Object-Oriented approach does not include classes does not mean that it is not what you call an Object-Oriented language.

Classes are used as a blueprint for objects in other languages, yes, but almost all that classes can do, can be achieved by a constructor function, the prototype chain, etc in JavaScript. You can see it as another implementation of classes.

There is no definition for an Object-Oriented language, I think.

Steven Parker
Steven Parker
231,210 Points

:point_right: I have to disagree on this one: JavaScript is an object-oriented language.

It's true that JavaScript was traditionally prototype-based instead of class-based, but that's just a different approach to object-oriented language design. It happens to be an approach that is uniquely useful and considered by some experts to be one of JavaScript's best features.

Now with ES2015, the keyword "class" has been added to the language, so the distinction from other object-oriented languages is even less apparent than before. But the fact that it is an object-oriented language was always clear.

Hi,

From what I've learnt so far, here at Treehouse, if I am not wrong, I think JS (ECMAScript) does not fully implement Object Oriented Programming.

In the C# Object course, If I understood correctly, the teacher says a object oriented language is the one that implements the following 4 core principles:

  • Encapsulation
  • Inheritance
  • Polymorphism
  • Abstraction

As far as I know, ECMAScript (JS) implements Encapsulation as you can hide implementation details and expose the set of operations to work with objects. It also implements inheritance through prototypes. It has polymorphism as you can, for example, override methods or make the same type of objects have different behaviours. However, perhaps for my lack of knowledge, I apologize in advance for that, I am not able to see how ECMAScript implements abstraction. If I understood correctly, In the C# course they say that abstraction means to think about SW in terms of objects and their public interface. I do not see any feature in the JS language to design the program with object interfaces first, and then write the code.

I hope it helps. Have a nice day, Edu

Steven Parker
Steven Parker
231,210 Points

JavaScript implements all 4 principles of object-oriented languages.

Take a look at this MDN page on Object-Oriented JavaScript for details about how all of the object-oriented language principles are implemented.

Note that the MDN page thoroughly makes its case without including any of the newer ES6 syntax.

Tom Geraghty
Tom Geraghty
24,174 Points

It might be worth reading the wiki article on it: https://en.wikipedia.org/wiki/Abstraction_(software_engineering)#Abstraction_in_object_oriented_programming

In object-oriented programming theory, abstraction involves the facility to define objects that represent abstract "actors" that can perform work, report on and change their state, and "communicate" with other objects in the system.

The class is an abstraction. By using the new keyword you are creating an instance of that abstract class. The instance can then be used by your program.

Static classes and static methods do exist. My knowledge on them is limited so I won't go on but it's worth checking out if you have the proclivity.

There's enough dogma in the world, we don't need to include it in programming discussions :)

Thanks for the link :)

For those who believe JavaScript is a object-oriented language, please watch this video starting at around 0:45.

Steven Parker
Steven Parker
231,210 Points

Guil's use of the word "true" is a bit misleading.

It might be even more confusing if you miss the fact that he makes quotes in the air with his fingers as he says it. His point would probably be more clear if you substitute the word "conventional". The introduction of the keyword "class" into the language blurs the distinction a bit, but JavaScript's object oriented methodology remains prototype-based vs. class-based as in more conventional OOP languages.

As MDN says, JavaScript is "Object-oriented to the core". It's just not "class-based".