Please note, this is a STATIC archive of website webdevelopmenttutorials.com from 20 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.

Tutorials

Learn web design and programming with our free video and text tutorials.

Web Designer? Design and market your own professional website with easy-to-use tools.

Javascript Objects Tutorial

Javascript is an object oriented programing (OOP) language.

An OOP is a programing language that is organized around objects. Objects have properties and methods.

Javascript uses periods (.) to seperate object names and property names. For example, an object called "Car", might have properties Car.new and Car.blue.

In large scripts, this allows you to create self-contained javascript objects, which allow you to reuse javascript code more often.

An object in javascript is an abstract container that is used to hold data. The data that is contained in the object can be a single number or a more complex data structure.

In javascript, you can create your own objects, or you can use predefined objects, such as "string", "date" and "array".

Properties

Each object has one or more properties. A property is a variable that is associated with that object.

In the javascript code example below, the length property of the string object is used to return the number of characters in the string.

<script type="text/javascript" language="javascript">

var txt="Hello World!";
document.write(txt.length);

</script>

The javascript code above outputs:

An objects can also be a property of another object. This object would be called a child object.

Methods

Objects can have methods. An object's method is a function that it can perform.

The javascript code example below uses the toUpperCase() method of the string object to display the text in uppercase letters.

<script type="text/javascript" language="javascript">

var str="Hello world!";
document.write(str.toUpperCase());

</script>

The javascript code above displays: