Saturday, August 20, 2011


  1. Welcome
    1. Introduction
    2. First Program
  2. Basics
    1. Placing the Code
    2. Lexical Structure
      1. Reserved Words
    3. Variables and Types
    4. Operators
    5. Control Structures
    6. Functions and Objects
    7. Event Handling
    8. Regular Expressions
  3. Advanced Topics
    1. Object Oriented Programming
      1. Constructors and Prototypes
      2. Inheritance
      3. Access Control
    2. Functional Programming in JavaScript
      1. Function Objects
      2. Anonymous Functions
      3. Closures
      4. Higher Order Functions
    3. Modular JavaScript
      1. Modules
      2. Namespaces
    4. Optimization
    5. Metaprogramming
    6. Bookmarklets
  4. Debugging
    1. JavaScript Debuggers
    2. Common Mistakes
    3. Debugging Methods
    4. Browser Bugs
  5. Dynamic Web Client Programming (DHTML)
    1. Runtime Document Manipulation
      1. Introduction to the Document Object Model (DOM)
      2. Finding Elements
      3. Adding Elements
      4. Changing Elements
      5. Changing Element Styles
      6. Removing Elements
    2. Event Handlers
      1. Simple Event Handlers
      2. W3C Event Handlers
      3. Extended Event Handlers
    3. Running Scripts at Page Load
    4. Soul Building Javascript
    5. XML and Javascript
      1. DOM Manipulation
      2. XSL Sprinkles
    6. DHTML Examples
  6. Advanced Web Client Programming
    1. Working with Images
    2. Working with Forms
    3. Working With Cookies
    4. Client-Server Programming (AJAX)
      1. XMLHttpRequest
      2. Handling HTML
      3. Handling JSON
      4. Handling XML
    5. Design Mode
  7. JavaScript Outside HTML
    1. ActionScript in Flash
    2. Adobe PDF Forms
    3. JSOSA for the Macintosh
    4. JScript in Microsoft WSH
  8. Standards and Best Practices
    1. Naming Conventions
    2. Code Structuring
    3. Accessibility
  9. Appendices
    1. Index
    2. Links
    3. Useful Software Tools
    4. History of JavaScript
    5. Contributors

JavaScript is a loosely typed language. What this means is that you can use the same variable for different types of information, but you may also have to check what type a variable is yourself if the differences matter. For example, if you wanted to add two numbers, but one variable turned out to be a string, the result wouldn't necessarily be what you expected.



[edit] Variable declaration

Variables are commonly explicitly declared by the var statement, as shown below:
var c;
The above variable is created, but has the default value of undefined. To be of value, the variable needs to be initialized:
var c = 0;
After being declared, a variable may be assigned a new value which will replace the old one:
c = 1;
But make sure to declare a variable with var before (or while) assigning to it; otherwise you will create a "scope bug."

[edit] Naming variables

When naming variables there are some rules that must be obeyed:
  • Upper case and lower case letters of the alphabet, underscores, and dollar signs can be used
  • Numbers are allowed after the first character
  • No other characters are allowed
  • Variable names are case sensitive: different case implies a different name
  • A variable may not be a reserved word

[edit] Primitive Types

Primitive types are types provided by the system, in this case by javascript. Primitive type for javascript are booleans, numbers and text. In addition to the primitive types, users may define their own classes.
The primitive types are treated by Javascript as value types and when you pass them around they go as values. Some types, such as string, allow method calls.

[edit] Boolean Type

Boolean variables can only have 2 possible values, true or false.
var mayday = false;
var birthday = true;

[edit] Numeric Types

You can use Integer and Float types on your variables, but they are treated as a numeric type.
var sal = 20;
var pal = 12.1;
In ECMA Javascript your number literals can go from 0 to -+1.79769e+308. And because 5e-324 is the smallest infinitesimal you can get, anything smaller is rounded to 0.

[edit] String Types

The String and char types are all strings, so you can build any string literal that you wished for.
var myName = "Some Name";
var myChar = 'f';

[edit] Complex Types

A complex type is an object, be it either standard or custom made. Its home is the heap and goes everywhere by reference.

[edit] Array Type

Main page: JavaScript/Arrays
In Javascript, all Arrays are untyped, so you can put everything you want in an Array and worry about that later. Arrays are objects, they have methods and properties you can invoke at will. (The ".length" property indicates how many things are currently in the array. If you add more things to the array, the value of the ".length" gets larger). You can build yourself an array by using the statement new followed by Array, as shown below.
var myArray = new Array(0, 2, 4);
var myOtherArray = new Array();
Arrays can also be created with the array notation, which uses square brackets:
var myArray = [0, 2, 4];
var myOtherArray = [];
Arrays are accessed using the square brackets:
myArray[2] = "Hello";
var text = myArray[2];
There is no limit to the number of items that can be stored in an array.

[edit] Object Types

An object within Javascript is created using the new operator:
var myObject = new Object();
Objects can also be created with the object notation, which uses curly braces:
var myObject = {};
JavaScript Objects can be built using inheritance and overriding, and you can use polymorphism. There are no scope modifiers, with all properties and methods having public access. More information on creating objects can be found in Object Oriented Programming.
You can access browser built-in objects and objects provided through browser JavaScript extensions.

No comments:

Post a Comment