
To define the same properties between many objects, you'll want to use a constructor function. Below is a table that summarizes a JavaScript representation of an EpicFailVideo object.
| Property | Data | Type |
|---|---|---|
| epicRating | 1 to 10 | Number |
| hasAnimals | true or false | Boolean |
this.epicRating = epicRating;
this.hasAnimals = hasAnimals;
}
var parkourFail = new EpicFailVideo(7, false);
var corgiFail = new EpicFailVideo(4, true);
console.log(parkourFail);
console.log(corgiFail);
As you can see, the constructor function is defined using a function expression. In other words, the variable EpicFailVideo is declared and then assigned a function with two parameters called epicRating and hasAnimals.
When the function is called, the data inside these parameters are stored inside the this.epicRating and this.hasAnimals properties respectively. Storing data within properties ensures any newly created object can access that data later.
After the constructor function definition, two objects are instantiated with the new keyword and their properties are initialized by calling the EpicFailVideo constructor function. After being instantiated and initialized, these objects are stored inside the parkourFail and corgiFail variables.
Finally, the two newly created objects are logged to the console.
- How to create tables
- What information suits tables
- How to represent complex data in tables
- table tag
- tr tag
- td tag
- Table headings
- th tag
- spanning columns
- spanninag rows
- thead tag
- tbody tag
- tfoot tag
To update the value ofproperties , use dot notation or square brackets they work on objects created on objects created using literal or constructor notation . To delete a property use the delete keywword.











