# JavaScript Objects
● Real Life Objects, Properties, and Methods.
In Real life, a car is an object.
A car has properties like weight and color, and methods like start and stop.
All cars have a same properties, but the property values differ from car to car.
All cars have the same methods, but the methods are performed at different times.
A car has properties like weight and color, and methods like start and stop.
<http://www.w3schools.com/js/js_objects.asp> |
All cars have the same methods, but the methods are performed at different times.
● JavaScript Objects
Objects are variables too. But objects can contain many values.
This code assign many values ( Flat, 500, white ) to a variable named car.
This code assign many values ( Flat, 500, white ) to a variable named car.
● Object Properties.
The name:values pairs are called properties.
Use the above example, properties are type, model and color. and property values are fiat, 500 and white.
Use the above example, properties are type, model and color. and property values are fiat, 500 and white.
● Object Methods
Methods are actions that can be performed on objects.
Methods are stored in properties as function definitions.
● Accessing Object Properties.
Accessing object properties in two ways.
- objectName.propertyName
- objectName["propertyName"]
● Do not declare Strings, Numbers, and Booleans as Objects.
When a JavaScript variable is declared with the keyword new, the variable is created as an object.
No comments:
Post a Comment