The Semi - Colon
JavaScript uses the semi-colon extensively. It is used to
terminate a line of code within a function or a variable
anywhere within the SCRIPT tags. It tells the JavaScript
parser and engine that the code on the first line should be
executed before executing the next line. While it isn't
necessary for absolutely every line, it is a good
programming convention to terminate every statement and
variable with a semi-colon. This takes the guesswork out of
executing your script. A semi-colon after every statement
and variable will ensure that the JavaScript parser doesn't
read your code wrong.
Because JavaScript is considered to be a "loosely typed"
language, leaving out a semi-colon will not throw an error.
It is this loosely typed functionality that is a great
selling point for JavaScript. Languages like C+ require
absolutely every line to be terminated with a semi-colon.
This strict adherence to a syntactical convention is what
makes working with the "higher languages" so annoying.
Examine the below example of a simple "Hello World"
function, written in JavaScript, which utilizes the semi-
colons in the proper places.
<SCRIPT LANGUAGE="JavaScript1.2">
<! --
function writeToScreen() {
document.write("Hello World !!!");
}
-- >
</SCRIPT>
This is obviously an incredibly simple example, but it shows
the correct placement of the semi-colon. Adhere to these
simple rules, and you'll have no problems in your future
scripting endeavors. Comment Statements
You've seen one use of the comment tags in the above SCRIPT
tag examples. The "<! -- and -- >" tags are comment tags
used to tell the browser not to write the textual content
within to the browser window. There are three types of
comment, and each is used a bit differently, as shown below.
- <! -- and -- > - This type comment statement can
only be used within the opening and closing SCRIPT tags, and
may comment out more than one line of content.
- /* and */ (Block of Comments) - The "Block of Comments"
tells the browser to disregard the rendering of the content
within the opening and closing tags. The content may span
more than one line.
- // (Single Line Comment) - The "Single Line Comment"
tells the browser to disregard the rendering of the content
within the opening and closing tags. The content may not
span more than one line. Keeping these simple rules in mind
when beginning your JavaScript code will not only speed
things up (less errors), but also make your code easy to
read and understand at a later time.
Syntax - Page 4
The JavaScript Chronicles
Data Types - Numbers
The JavaScript Chronicles
JavaScript Introduction
Part 2: Data Types
Part 3: Arrays
Part 4: Operators
Part 5: Conditional Statements
Part 6: JavaScript Functions
Part 7: Pattern Matching - The RegExp Object
Part 8: Introduction to Server Side JavaScript
Part 9: Server Side JavaScript Mail Sending
Part 10: Server Side JavaScript and File Manipulation
Part 11: Working with Forms in JavaScript
Part 12: Getting to Know Dynamic HTML
|