Helping ordinary people create extraordinary websites!

JavaScript Syntax Reference

Now that you've learned all the elements of JavaScript, you will often find you can recall what code means, but have trouble remembering the syntax. We've put together this handy syntax reference, covering everything we've learned so far.

Bookmark this and refer back to it when writing JavaScript code; it will help you master the syntax quicker. For example, if you can't remember how to write a certain loop, just check the reference.

var y = 10, x = "A string value";
z = 10.9; // A float

/* Function write_to_document()
This function will write the string parameter outputtext
out to the document through document.write(), and if the
second boolean do_alert parameter is specified, alert() */

function write_to_document(outputtext, do_alert = false) {
// If do_alert is not specified, it defaults to false
document.write(text);
if (do_alert) {
alert(text); // Display a popup alert box
}
}

for (i=0;i<2;i++) {
write_to_document("Here's some text");
}

while (i != "stop") {
// This will stop on the first loop.
i = "stop";
}

alert(i); // This will create a popup saying "stop"

Now that you've learned the language, head over to our Advanced JavaScript page for tips and tricks on common JavaScript issues.

« JavaScript Comments Advanced JavaScript »


More JavaScript Tutorials:
» JavaScript Form Input Validation and Correction
» A Simple Image/Link Rollover in Javascript
» Ensuring Two Form Fields Have Identical Information
» Redirecting URL
» Color Code Converter
» How to Set up a Randomizing Function