C++ an OOP language, to create an object, one must first instantiate a class and then implement a constructor which then creates an object.
In this example is a class
MyClass, which has an attribute of the integer
myNum and string
myString. However, an object doesn’t exist until the constructor
int main() creates
myObj from the class itself,
MyClass myObj;and assigns values,
myObj.myNum = 15; that any number can be returned, which is done at
cout << myObj.myNum << "\n" to return the value of
15. The integer belongs to
var; if an engineer working from an OOP language started coding in JS, expecting constructors they would get confused very quickly.
person is an object, without a class; it is one instance of object which has all of its attributes (in this case we call them props or properties) assigned directly within curly braces…and when
person.firstName is assigned to the screen via
document.getElementById(“demo”).innerHTML a new
<div> is made and the object
firstName is assigned as text.
The problem with this method is each object is unique and cannot be repeated through this method. We need to declared all the data explicitly.
This is very DRY 🏜