Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

JavaScript QuickStart: Elements of JavaScript : Page 4

JavaScript is cropping up everywhere and if you want to learn to use it, you'll need to understand these essential elements.


advertisement

Statements
A statement is a single line of instruction to the computer.

You might think of a statement as being a bit like a JavaScript sentence, made up of objects, expressions, variables, and events/eventhandlers.

Each statement should end with a semicolon, although sometimes people will omit the semicolon and end with a hard return.



For example, you might create a statement that tests to see if the value in the variable named "frogs" is equal to the phrase "green":

frogs == "green";

Or, you might use a statement to write a line of text into your page, using the "document.write" method.

document.write ("Many frogs are green, but the red-toed tree piper is yellow and red.");

Functions
A function is a series of statements grouped together to perform a specific task. You give the function a name and can call it by name.

In the real world, driving a car is a function with a series of steps: putting the key into the ignition, turning the key, and shifting gears from "park" into "drive." In JavaScript, you might create a function to test items in a list, to determine whether the reader had entered a certain value, and if the reader has, to post a message that says "guess again!"

You can tell a function definiton because it begins with the command "function", and contains a series of statements within braces.

function greeting()   {
  document.write("Welcome to the Underwater World<br>");
  document.write(of<br>");
  document.write(<font color=#ffff99>The Happy Squid<br>");
}

This is a simple function. The function is named "greeting" and it writes three lines of text into the HTML document.





Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date