logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Action Movies
Bible Basics
Houseplants
Romance Movies
Creativity
Family Travel
Southwest USA


dailyclick
All times in EST

Full Schedule
g
g JavaScript / Java Site

BellaOnline's JavaScript / Java Editor

g

document.write("Hello World") and other cases of something-dot-somethingelse

Guest Author - Julie L Baumler

When you look at a JavaScript program, you usually see a bunch of things of the form word dot word parenthesis (maybe with something in the parenthesis or more word, dot pairs.) For instance, in the program in the article A First JavaScript Program (available here), we have several such lines. I'm going to look at document.write("Hello World!"), because it makes a particularly good example. So, what is this and what does it mean? These are examples of objects and methods. Although understanding objects and methods is important if you want to really become a good programmer in object-based (ie JavaScript) and object-oriented (ie Java) languages, knowing how to use them allows you to start reusing other people's code. I also find that it is easier to grasp the theory behind objects and methods after playing with them a little bit. This article should help you gain enough understanding to recognize objects and methods and use a few simple methods.

The line document.write("Hello world!") is a good example to learn from because it illustrates the basic concepts in a very basic way and it is very useful for simple programs. Objects are virtual items in your program. In our example, we are dealing with the document object. In a web page, this is the actual contents of the page (and technically, this is part of the W3C Document Object Model, DOM, not specifically JavaScript, but JavaScript interacts with the DOM.) Keep in mind for the future that not all objects tie in to visible things so clearly, but it's always nice to start with the easy part. Methods belong to specific objects and are called as object.method_name(properties and values). In this case we are looking at the write() method of the document - document.write().

Methods can accept properties and values that tell the method more specifically what to do, these go in the parenthesis. For instance, you might tell a child to sit down or you might want to tell them to sit down right now in the blue chair. The "right now" and "blue chair" part would be properties and values. Just like a child unfamiliar with the word might just look at you confused if you told them to sit down on the chaise, you can only tell an object or method about activities and things they are familiar with (unless you teach them about them first.) In our case, we are passing the value "Hello world!".

The document.write() method assumes anything you pass it is text, HTML, or JavaScript that it should print to the web page. So our example line document.write("Hello world!") prints Hello world! on the page. If you want to write anything on a web page using JavaScript, you can do it simply by putting it in your program between the parenthesis of a document.write() method call. You can include one or more arguments to document.write() and they will just be displayed in the order given. Different objects have different methods and different methods use the information they are given differently (and sometimes objects have sub-objects), but the same basic pattern of object.method() applies.

REFERENCE

document.write( argument_one[, argument_two, ...])

writes the given arguments, which can be any combination of text, HTML, and JavaScript , to the document (web page).


The W3C Document Object Model (DOM)
This site needs an editor - click to learn more!

Add document%2Ewrite%28%22Hello+World%22%29+and+other+cases+of+something%2Ddot%2Dsomethingelse to Twitter Add document%2Ewrite%28%22Hello+World%22%29+and+other+cases+of+something%2Ddot%2Dsomethingelse to Facebook Add document%2Ewrite%28%22Hello+World%22%29+and+other+cases+of+something%2Ddot%2Dsomethingelse to MySpace Add document%2Ewrite%28%22Hello+World%22%29+and+other+cases+of+something%2Ddot%2Dsomethingelse to Del.icio.us Digg document%2Ewrite%28%22Hello+World%22%29+and+other+cases+of+something%2Ddot%2Dsomethingelse Add document%2Ewrite%28%22Hello+World%22%29+and+other+cases+of+something%2Ddot%2Dsomethingelse to Yahoo My Web Add document%2Ewrite%28%22Hello+World%22%29+and+other+cases+of+something%2Ddot%2Dsomethingelse to Google Bookmarks Add document%2Ewrite%28%22Hello+World%22%29+and+other+cases+of+something%2Ddot%2Dsomethingelse to Stumbleupon Add document%2Ewrite%28%22Hello+World%22%29+and+other+cases+of+something%2Ddot%2Dsomethingelse to Reddit




A First JavaScript Program
Beginners Resources
JavaScript/Java Newsletter
RSS
Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map


For FREE email updates, subscribe to the JavaScript / Java Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Julie L Baumler. All rights reserved.
This content was written by Julie L Baumler. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


g features
Hearing Dog Tool - Adding Randomness

Hearing Dog Training Tool setTimeout()

GCJ - an Independant Java Implementation

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor