Lesson 4: Why JavaScript is object-based


JavaScript is an object-based program rather than object-oriented. The reason is because you don't have to worry about the intricate details of how objects work. All you have to do is define them and everything is automatically done for you. This lesson will cover how JavaScript handles multiple objects.

You will find it easier to understand how JavaScript handles multiple objects if you read backwards like this:


document.forms[0].birthdate.value

This is an example of a form. Start with the two methods between the first dot reading backward like this: "form 0 of the document" This looks at form 0 of the document. Now move to the second part: "look for a value in birthdate" Notice that once we specified which form in the document to look for, JavaScript is going deeper to look for a value under birthdate. With little practice you will see that this is not that confusing.

Now we will provide an example of how JavaScript does this:

[HTML]
[HEAD]
[BODY]
[FORM]
[INPUT TYPE="radio" NAME="sex"]Male[BR]
[INPUT TYPE="radio" NAME="sex"]Female[BR]
Enter birthdate: [INPUT TYPE="text" NAME="birthdate" SIZE="10"]
[/FORM]

[SCRIPT LANGUAGE="JavaScript"]
document.write(document.forms[0].birthdate.value)
[/SCRIPT]
[/BODY]
[/HTML]

In order to see what this does click here. Click on Lesson 5 to continue.