Introduction to JavaScript Tutorial
By Neil Williams2007-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;This code will cause a Javascript error:
var test=4;
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 commentJavascript code in HTML pages should be contained within HTML comment tags:
/* this is a
multi-line comment */
<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() {};
| 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 | |
| catch | finally |
| class | super |
| const | throw |
| debugger | try |
| 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
