1. Home
  2. Computing & Technology
  3. JavaScript

JavaScript Objects
The Difference Between Methods and Properties

By Stephen Chapman, About.com

The two basic types of variables that can be contained within an object variable are called methods and properties. These actually correspond to types of variables that we have already seen and it is only because they are given different names when you reference them within an object that you don't already know exactly what they are. A method is code that can be run. It defines one of the ways in which a given object can behave. A method is basically a function that is attached to and interacts directly with a specific object or type of object.

Properties are all of the other types of variables that JavaScript supports with the only difference being that their scope is defined in terms of the object that they belong to rather than being local or global. Properties define the current state of the object and running a particular method belonging to the object is normally done in order to update the state of one or more of the properties of the object.

While not strictly accurate, you wont go too far wrong if you think of the properties and methods of an object as being functions and variables whose scope is contained within that object but which can be referenced from outside of that scope using the period notation after the name of the object itself.

Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript
  4. Reference
  5. Methoda and Properties>

©2009 About.com, a part of The New York Times Company.

All rights reserved.