Welcome to Computer Class: Learn Python, Javascript, HTML, CSS, DBMS Fundamental of Computer
Online code editor available hare to practice coding in Javascript, Python etc
All tips and tricks for beginners available
A JavaScript Object may be a real life object or thing and its different kinds of looks, actions, varieties are the different properties of the object. The different ways of doing the actions are the methods of the object.
For example, a laptop is an object, its different model, size, color, memory are the properties and its processing speed, the way of functioning or different operating systems are the different methods.
The properties and method's name of different laptops are same but values of these properties and methods may be different.
An object may be a variable too, which can contain many values:
For example:
Try it yourself editor
Output
An object may contain many values as a variable. The values are written by name:value pairs
For example:
Try it yourself editor
Output
A JavaScript object can be created as literals.
For example:
Try it yourself editor
Output
In above examples, we can see that the laptop is an object, its type, model and color are properties. HP, pavilion and white are values of the properties.
We can access an object property by two ways. These are:
object.property or
object["property"]
See examples
Try it yourself editor
Output
This is the first way as object.property
Try it yourself editor
Output
This is the second way as object["property"]
An object property can be defined as the container of the values.
Object Methods : Methods are the actions performed by an object or on an object. Methods are stored in a property as function definition.
For example:
var person = { firstName: "Peter", lastName : "Johnson",