How to Use Classes and Objects in JavaScript


show more Classes and objects are the foundational building blocks to object-oriented programming, but are often confused with other data structures such as numbers and booleans. The JavaScript tutorial in Foundations of Programming Fundamentals covers the difference between objects and variables and discusses object instantiation and different object types. show less
please wait ...

Using classes and objects

The best way to start getting familiar with classes and objects is to begin by using classes that are already defined in your language and just creating objects from those built-in classes. We can later define our own classes and create objects from those classes. Now this sounds complex. It really isn't. In fact, we've already done it. So in JavaScript, when you make an array variable, you have made an object. When you make a regular expression variable, you've made an object.

These are both built-in objects in JavaScript. Now on the other hand, when you make a variable that's a number or a variable that's a Boolean, these are not objects. These are what can be referred to as primitives. Primitives really just store a value. That's it. But as we've seen, when you have got an object, this is not just a dumping ground for data. When you have an array, you can ask things of it. They have properties like length and they have methods. We can ask them to sort themsel...

Using classes and objects
Video duration: 6m 28s 4h 47m Beginner

Viewers:

Classes and objects are the foundational building blocks to object-oriented programming, but are often confused with other data structures such as numbers and booleans. The JavaScript tutorial in Foundations of Programming Fundamentals covers the difference between objects and variables and discusses object instantiation and different object types.

Subjects:
Developer Web
Author:
please wait ...