Object Literal Properties and Method in Javascript

 Object Literal Properties and Method in Javascript

In this article we are goanna to see about Object Literal Properties and Method 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.



Properties

A property of an object is some piece of named data it contains. These are accessed with dot operator applied to an object alternative to the dot operator is the array[ ] operator.

Syntax:  object_name.property_name

Ex:

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

var person = { };

person[“fname”] = “Raj”;   or person.fname =  “Raj”;

document.write(person.fname);

document.write(person[‘fname’]);

delete person.fname

Method

Object members that are functions are called methods. These are accessed with dot operator applied to an object alternative to the dot operator is the array[ ] operator.

Syntax:  object_name.method_name( );

Ex:

var person = { fname: 'Raj’, lname: 'Kumar’, fullname: function(){return (“Hello world”}}

var person = { };

person[“fullname”] = function(){return (“Hello world”)};  

person.fullname = function(){return (“Hello world”)}; 

document.write(person.fullname());

document.write(person[‘fullname’]());

       delete person.fname()


Share:

0 comments

Please leave your comments...... Thanks