Presented by: Aakash Biswas
Duration: 12.16 minutes
Watch Tutorial 1: • Learn JavaScript (Tutorial 1)
Watch Tutorial 2: • Learn JavaScript (Tutorial 2)
Watch Tutorial 3: • Learn JavaScript (Tutorial 3)
Watch Tutorial 4: • Learn JavaScript (Tutorial 4)
Watch Tutorial 5: • Learn JavaScript (Tutorial 5)
Watch Tutorial 6: • Learn JavaScript (Tutorial 6)
Watch Tutorial 7: • Learn JavaScript (Tutorial 7)
Objects
Objects are like variables they can hold values. But objects can contain many values.
The values are written as name : value pairs which are separated by a colon.
An object is a collection of named values
The named values, are called properties.
Methods are actions that can be performed on objects.
Object properties can be both primitive values, other objects, and functions
An object method is an object property containing a function definition.
In JS you can define and create your own objects.
There are different ways to create new objects:
1)Define and create a single object, using an object literal.
2)Define and create a single object, with the keyword new.
3)Define an object constructor, and then create objects of the constructed type.
Using an object literal to create an object.
You will both define and create an object in one statement.
An object literal is a list of name:value pairs, like name: Aakash inside curly braces {}.
Spaces and line breaks are not important. An object definition can span multiple lines
Objects are mutable. They are addressed by reference and not by value.
JavaScript Properties
Properties are the values associated with a JS object.
A JS object is a collection of unordered properties.
Properties can be changed, added, and deleted. But some are read only.
Accessing JS Properties
To access the property of an object:
1)objectName.property
2)objectName["property"]
3)objectName[expression]
The delete keyword deletes a property from an object.
The delete keyword deletes both the value of the property and the property itself.
After deleting the property cannot be used before it is added back again.
The delete operator is designed to be used on object properties.
It has no effect on variables or functions.
The delete operator should not be used on predefined JS object properties.
Warning: It can crash your application.!
Property Attributes
All properties have a name and they also have a value.
The value is one of the property's attributes. Other attributes are:
1)enumerable
2)configurable
3)writable
These attributes define how the property can be accessed if it is readable? Or if it is writable?
In JS all attributes can be read, but only the value attribute can be changed and only if the property is writable.
JS Methods
JS methods are the actions that can be performed on objects.
A JS method is a property containing a function definition.
JavaScript Prototypes
All JS objects inherit the properties and methods from their prototype.
Objects created using an object literal, or with new Object(), inherit from a prototype called Object.prototype.
Objects created with new Date() inherit the Date.prototype.
The Object.prototype is on the top of the prototype chain.
All JS objects like Date, Array, RegExp, Function etc. Inherit from the Object.prototype.