Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Your Email:

Introduction to JavaScript Tutorial

By Neil Williams
2007-11-09


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;


Tutorial Pages:
» It's flavours and versions
» Structure and syntax
» Data types and objects
» Functions and operators
» JavaScript Statements A-F
» JavaScript Statements G-Z
» JavaScript Events
» JavaScript Global Properties
» Javascript code to identify your browser
» Redirecting the browser once identified


Copyright © Neil Williams


 | Bookmark
Related Tutorials:
» JavaScript Debugging Techniques with Firebug
» Striped Tables Using JavaScript
» Opening PDFs in a New Window with JavaScript
» Essential Javascript -- A Javascript Tutorial
» Submit Forms Conditionally using JavaScript
» How to Setup a Randomising Function