Javascript

Structure and syntax

Case Sensitivity
All keywords like var or function must be in lowercase. All variable names, function names and identifiers are case sensitive. The following two variables are separate and independent of each other:

var Test = 6;
var test=4;
This code will cause a Javascript error:
function Test() {alert("Testing");}
function show_alert() {tesT();}

Whitespace
Like most programming and scripting languages, Javascript requires one space between keywords, names and identifiers. Extra spaces are ignored so you can use tabs and spaces wherever you need to make your code easier to read and debug.

Semi-colons
Every line of Javascript must end in a semi-colon ;
Blank lines don't need sem-colons.

Comments
You can use C and C++ style comments:

// this is a single line comment
/* this is a
multi-line comment */
Javascript code in HTML pages should be contained within HTML comment tags:
<script language="Javascript" type="text/javascript">
<!--
// Javascript here
//   -->
</script>

Identifiers (Variable names, function names, labels.)
The first character in an identifier name must not be a digit. Javascript 1.0 does not allow identifiers to contain the $ character. The following are not legal identifier names:

var $value;
function 1way() {};
Javascript Keywords
break for this
case function true
continue if typeof
default import var
delete in void
do new while
else null with
export return
false switch
Reserved for future use
catchfinally
classsuper
constthrow
debuggertry
enum
extends

Variables
Declare variables using the keyword var. Javascript variables have no explicit data type and can contain data of any type.

var mynumber;
var mystring;
var myboolean;


This is part of www.codehelp.co.uk Copyright © 1998-2004 Neil Williams
See the file about.html for copying conditions.