<< Home

What are objects and how are they used?

Objects are items that can be used to add functionality to a web page. In the example below we use the built in string object to hold a string of text. You can name a string object what you like. In the example below it is called txt. We can then use the methods associated with this objects to see what properties the object has.

Another example of an object is the Date object. One example of using the date object would be to display today's date on your page.

Example of string object:

<script type="text/javascript">
var txt="this is a text object in javascript we will find the lenth of this string";
document.write(txt.length);
</script>

The length of the string is shown here:

image missing

For the assignment you need to show that you can use and example and explain it's usage.