Constructors and Properties

In JavaScript classes, we put constructors inside of them as follows…

class Animal {
    constructor(name){
        this.name = name;
    } }
let gorilla = new Animal(‘Bongo’);
console.log(gorilla.name); 

The output would be “Bongo”. This syntax should be very familiar to those coming from traditional OO languages, such as C#.

Happy Coding!

Clay Hess

More To Explore

Share This Post

small_c_popup.png

Need help?

Let's have a chat...


Login

Jump Back In!

Here at Webolution Designs, we love to learn. This includes sharing things we have learned with you. 

Register

Begin Your Learning Journey Today!

Come back inside to continue your learning journey.