Introduction
Overview
History
Advice
Books
Tutorials
Source Code
Top 100
Reference

Beginners
Sample Code
IDE
Syntax
Variables
Boolean Logic
Strings
Arrays
Conditional Flow

Intermediate
Date-Time
Math
Functions
Event Handlers
Error Handling

Advanced
Objects
Dynamic HTML
Cookies
Multimedia
CGI
Java Applets
Distribution

Community
Web Sites
Mailing Lists
USENET
Vendors
News

GBIC >> JavaScript >> Syntax
Case Sensitivity
JavaScript is case-sensitive. The variables x and X are not the same variable.

White Space
Like HTML, JavaScript ignores spaces and line breaks. This means that statements can be split over multiple lines.

Ending a JavaScript Statement
Typically, a single JavaScript statement is placed on a line, but multiple JavaScript statements may be used on a single line. Multiple JavaScript statements on a single line must be separated by a semicolon.

If a single JavaScript statement is placed on a single line, the line does not have to end in a semicolon but it is considered good practice to always use the semicolon.

Code Blocks
JavaScript uses the curly brace pair, { }, to indicate blocks of code, as shown in this example:

{
x = 5
}

The curly braces can go on separate lines or be written on the same line as the code, such as in this example:

{ x = 5 }

Code blocks can be nested to any depth.

Functions
JavaScript supports code which may be called over and over, called functions. Functions are written as:

function MyFunction (arg1, arg2, arg3)
   { Code Block }

When calling JavaScript functions, the parentheses are required, even if there are no arguments.

Strings
JavaScript strings may be coded using either single or double quotes, as in this example:

x = "122"
x = 'abc'
The availability of multiple quote operators allows nesting of quotes, as in this example:

x = "I said 'Hello' to you!"

Comments
Any text to the right of a pair of forward slashes is treated as comments and is ignored during execution. JavaScript editors will normally highlight comments as colored text (usually green). Here's an example of code and comments on the same line:

x = 5    //comments can go behind two forward slashes

JavaScript also supports multiline comments, which are inclosed by the /* and */ tags, as in this example:

x = 5
/*
Comments can go on any number of 
lines between these two tags 
*/
y = 5