Highlighted brick wall with neon inscription constructor

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

Share this post

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email
Skip to content