DEV Community

Brittany
Brittany

Posted on

Day 89 : #100DaysofCode - JS Objects & Fizzbuzz

Today I began to review Javascript objects and constructors via my bootcamp and FreeCodeCamp. I am almost halfway through the FreeCodeCamp lessons and hope to finish by tonight or tomorrow morning.

Alt Text

Some notes that I took are:

Constructors are functions that create new objects. They help us to define properties and behaviors that will belong to a new object.

A sample constructor:


function Person(firstName, lastName) {
  this.firstName = firstName,
  this.lastName = lastName,
  this.age = 23

}

let sally = new Person()
Enter fullscreen mode Exit fullscreen mode

The sally object is now an instance of the Person constructor. You can check this by running:

karen instanceof Person; // => false
sally instanceof Person; // => true
john instanceof Person; // => false
Enter fullscreen mode Exit fullscreen mode

All objects have properties. Ownproperties are defined directly on the object instance itself. And prototype properties are defined on the prototype.

function Person(firstName, lastName) {
  this.firstName = firstName;  //own property
  this.lastName = lastName;  //own property
}

Person.prototype.age = 25; // prototype property

let will = new Person("Will, Smith");
Enter fullscreen mode Exit fullscreen mode

I learned a lot about javascript objects and constructors and cant wait to learn more.

In addition, I was able to complete the FizzBuzz problem using Javascript. I plan to start to do more challenges and algorithms as I learn more.

As always, thanks for reading!

Sincerely,
Brittany

Top comments (0)