www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons JavaScript Objects and Classes Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24
Lesson 25
Lesson 26
Lesson 27
Lesson 28
Lesson 29
Lesson 30
Lesson 31
Lesson 32
Lesson 33
Lesson 34
Lesson 35
Lesson 36
Lesson 37
Lesson 38
Lesson 39
Lesson 40
Lesson 41
Lesson 42
Lesson 43
Lesson 44
Lesson 45
Lesson 46
Lesson 47
Lesson 48
Lesson 49

Simply speaking an objejct is a collection of properties and functions. Objects are very useful to organise data or information.

JavaScript has a number of useful built-in objects for use in our programs for example Data, string, array, etc. Recall that in the previous lesson we worked with a number of array properties and functions. In JavaScript we have the liberty to create our own objects too.

How to create objects in JavaScript?
It is very simple. We create an object in JavaScript with the new operator followed by the object name and a pair of parenthesis. The following line of code creates a Date object:

var dt = new Date();

Accessing Object Properties
The syntax for accessing a property of an object is:

objectName.propertyName ;

The following code demonstrates the use of the length property of the string object:

var domain = "pickatutorial.com";
var len= domain.length;
// the variable len now has the value 17

Calling / Invoking Object Functions
Functions usually perform some action on the object properties. The syntax for invoking a function on some object is as under:


The following code converts our text to lowercase:

var domain = "PICKATUTORIAL.COM";
var lower = domain.toLowerCase();
// the value of variable lower now equals pickatutorial.com

Important note about JavaScript Classes
If you have some prior programming experience of any object oriented programming language like c++, you may have an idea of classes. The concept of classes is very integral to the concept of objects in any object oriented programming langauge.

As of this writing JavaScript is not a FULL object oriented programming language and, therefore, we do not and cannot define classes in JavaScript. JavaScript is prototype based, not class based.

Next >>> Lesson No. 19: JavaScript Objects and Classes 2

Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.