Objects in Javascript

 Objects in Javascript

In this article we are goanna to see about Objects in Javascript and where we use these. which is most important when you are going to start your career in JavaScript. Please ready and enjoy this article if you want to give any feedback about your experience, we welcome.


An object is a collection of properties, and a property is an association between a name (or key) and a value. A property's value can be a function, in which case the property is known as a method. In addition to objects that are predefined in the browser, you can define your own objects. 

Syntax:

objectName.propertyName

Ex:

var person = { fname: 'Raj’, lname: 'Kumar’, age: 25 };

document.write(person.fname);

document.write(person.lname);

Almost "everything" is an object javascript.

Booleans can be objects (if defined with the new keyword)

Numbers can be objects (if defined with the new keyword)

Strings can be objects (if defined with the new keyword)

Dates are always objects

Maths are always objects

Regular expressions are always objects

Arrays are always objects

Functions are always objects

Objects are always objects

All JavaScript values, except primitives, are objects

Declaration and initialization of Object:

Syntax:

var object_name = { };

Ex:

var person = { };

person[‘fname’] = “Rajesh”;

person[‘lname’] = “Kumar”;

person[‘age’] = 26

document.write(person.fname);



Share:

0 comments

Please leave your comments...... Thanks