Javascript - Objects

Javascript - Objects

Publish Date: Jul 29
1 0

Objects:

programming element that groups data with relevant operations/behaviors

In real life, objects are things like : houses, cars, people, animals, or any other subjects.

Object Properties:

An object is a collection of properties, and a property is an association between a name (or key) and a value

A real life car has properties like weight and color

Object method:

Object Methods in JavaScript can be accessed by using functions. Functions in JavaScript are stored as property values. The objects can also be called without using brackets ().

A real life car has methods like start and stop:
car.start(), car.drive(), car.brake(), car.stop()

Difference between js variables and js objects:

Javascript variables are containers for data values.

Objects are variables too.. but objects contain many values.

const car = {type:"fiat", model:"500", color:"white"};

const keyword is the common practice to declare objects.

Object literal:

An Object Literal is a list of name:value pairs contain inside an object.

const person = {
first name: "john",
last name: "Doe",
id : 5566,
fullName : function() {
return this.firstName + " " + this.lastName; 
}
};
Enter fullscreen mode Exit fullscreen mode

to be discussed....

Comments 0 total

    Add comment