Exforsys

JavaScript Tutorial

  1. JavaScript Browser Objects Part 2
  2. JavaScript Frame object
  3. JavaScript Form Object
  4. JavaScript FileUpload Object
  5. JavaScript Event Object Properties and Methods
  6. JavaScript Event Object
  7. JavaScript Elements and Embed Objects
  8. JavaScript Applet Objects
  9. JavaScript Browser Objects
  10. JavaScript Object Oriented Features
  11. JavaScript Window Object Open Method Part 2
  12. JavaScript Window Object Open Method
  13. JavaScript Window Object Timeout Methods
  14. JavaScript Location Object
  15. JavaScript Location Object Properties
  16. JavaScript History Object Properties and Methods
  17. JavaScript Document Object Methods Part II
  18. JavaScript Document Object Methods Part I
  19. JavaScript Document Object Properties
  20. JavaScript Document Object
  21. JavaScript Windows Object Properties Part II
  22. JavaScript Windows Object Properties Part I
  23. JavaScript DOM Window Object
  24. Working with JavaScript DOM Objects
  25. JavaScript Array Object Methods – Part II
  26. JavaScript Array Object
  27. JavaScript Array Object Methods – Part I
  28. JavaScript Boolean Object
  29. JavaScript OnError Event
  30. JavaScript Exception Handling – Part II
  31. JavaScript Exception Handling – Part I
  32. JavaScript Event Handler
  33. JavaScript Events Handling
  34. JavaScript Array Operations
  35. JavaScript Two Dimensional Arrays
  36. Passing values to JavaScript Function
  37. JavaScript Functions
  38. JavaScript Arrays
  39. JavaScript Iterative Structures - Part II
  40. JavaScript Iterative Structures - Part I
  41. JavaScript Math Object
  42. JavaScript Date Object
  43. JavaScript String Object
  44. JavaScript Objects
  45. JavaScript Confirm Box
  46. JavaScript Alert Box
  47. JavaScript Conditional Statements Part 2
  48. JavaScript Conditional Statements Part 1
  49. How to use JavaScript in HTML page
  50. JavaScript Variables
  51. JavaScript Features
  52. JavaScript Introduction

Ads


Home arrow Technical Training arrow JavaScript Tutorial

JavaScript Objects

Author : Exforsys Inc.     Published on: 12th Aug 2007

JavaScript Objects

Object oriented Programming in an important aspect of JavaScript. It is possible to use built-in objects available in JavaScript.  It is also possible for a JavaScript programmer to define his own objects and variable types. In this JavaScript tutorial, you will learn how to make use of built-in objects available in JavaScript.

Ads

Built-in objects in JavaScript:

Some of the built-in objects available in JavaScript are:

  • Date
  • Math
  • String
  • Array
  • Object

Of the above objects, the most widely used one is the String object.

Objects are nothing but special kind of data. Each object has Properties and Methods associated with it.

Properties of an Object:

Property is the value that is tagged to the object. For example let us consider one of the properties associated with the most popularly used String object - the length property.   Length property of the string object returns the length of the string, that is in other words the number of characters present in the string.

General syntax of using the length property of the string object is as below:

variablename.length

Here variablename is the name of the variable to which the string is assigned and length is the keyword.

For example consider the JavaScript below:


<html>
   <
body>
      <
script type="text/javascript">
         var exf="Welcome"
         document.write(exf.length)

      </script>
   </
body>
</
html>

The output of the above is

7

We see that the property of an object is the value associated with the object.

Method of an Object:

Method of an object refers to the actions than can be performed on the object. For example in String Object there are several methods available in JavaScript.

Some of the Methods associated with String Object are:

toUpperCase()
toLowerCase()
substring()
indexOf
lastIndexOf

All these methods are used to perform actions on the String object.

For example the substring method of the String Object in JavaScript is used for extracting a specific portion of the string.

If a programmer wants the value of String object in lowercase then the method toLowerCase() is used on String Object

To convert a string to upper case, the method toUpperCase() is used.

If a programmer wants to know the position of a characters or group of characters in a String Object it can be determined by applying indexof method to the String.

Example to understand how method can be used in an Object.

In the example below, we have used toUpperCase method of String object.


<html>
   <
body>
      <
script type="text/javascript">
         var exf="Welcome"
         document.write(exf.toUpperCase())

      </script>
   </
body>
</
html>

Ads

The output of the above script is

WELCOME

In the above script since the method toUpperCase is applied to the string object exf which has value initialized as Welcome all letters get converted as upper case and hence the output is as above.



 
This tutorial is part of a JavaScript Tutorial tutorial series. Read it from the beginning and learn yourself.

JavaScript Tutorial

  1. JavaScript Browser Objects Part 2
  2. JavaScript Frame object
  3. JavaScript Form Object
  4. JavaScript FileUpload Object
  5. JavaScript Event Object Properties and Methods
  6. JavaScript Event Object
  7. JavaScript Elements and Embed Objects
  8. JavaScript Applet Objects
  9. JavaScript Browser Objects
  10. JavaScript Object Oriented Features
  11. JavaScript Window Object Open Method Part 2
  12. JavaScript Window Object Open Method
  13. JavaScript Window Object Timeout Methods
  14. JavaScript Location Object
  15. JavaScript Location Object Properties
  16. JavaScript History Object Properties and Methods
  17. JavaScript Document Object Methods Part II
  18. JavaScript Document Object Methods Part I
  19. JavaScript Document Object Properties
  20. JavaScript Document Object
  21. JavaScript Windows Object Properties Part II
  22. JavaScript Windows Object Properties Part I
  23. JavaScript DOM Window Object
  24. Working with JavaScript DOM Objects
  25. JavaScript Array Object Methods – Part II
  26. JavaScript Array Object
  27. JavaScript Array Object Methods – Part I
  28. JavaScript Boolean Object
  29. JavaScript OnError Event
  30. JavaScript Exception Handling – Part II
  31. JavaScript Exception Handling – Part I
  32. JavaScript Event Handler
  33. JavaScript Events Handling
  34. JavaScript Array Operations
  35. JavaScript Two Dimensional Arrays
  36. Passing values to JavaScript Function
  37. JavaScript Functions
  38. JavaScript Arrays
  39. JavaScript Iterative Structures - Part II
  40. JavaScript Iterative Structures - Part I
  41. JavaScript Math Object
  42. JavaScript Date Object
  43. JavaScript String Object
  44. JavaScript Objects
  45. JavaScript Confirm Box
  46. JavaScript Alert Box
  47. JavaScript Conditional Statements Part 2
  48. JavaScript Conditional Statements Part 1
  49. How to use JavaScript in HTML page
  50. JavaScript Variables
  51. JavaScript Features
  52. JavaScript Introduction
 

Comments