Javascript objects method 1 1

Javascript objects method 1

//simple function
function vehicle(name,maker,engine){
    this.name = name;
    this.maker = maker;
    this.engine = engine;
}
//new keyword to create an object
let car  = new vehicle('GT','BMW','1998cc');
//property accessors
console.log(car.name);
console.log(car.maker);
console.log(car['engine']);

Here is what the above code is Doing:
1. We have created a simple function called vehicle.
2. We have created an object called car using the new keyword.
3. We have accessed the properties of the car object using the dot notation and the bracket notation.

Similar Posts