javascriptcheatsheet - JavaScript cheat sheet Holmer Hemsen...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: JavaScript cheat sheet Holmer Hemsen NISLab University of Southern Denmark November 1, 2002 1 JavaScript Document Template A JavaScript can be included both in the header and/or the body of the document, the choice depends on the task. There can be several JavaScripts in a document. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>JavaScript Template</title> <script language="javascript" type="text/javascript"> <!-- Hide script from old browsers /* * Author: Firstname Lastname <email> * Date: * Version: * Last modified: * * Purpose: Description of the problem the program was written to solve. * Known Bugs: */ // End hiding script from old browsers --> </script> <noscript> <b>You dont have JavaScript enabled or your browser does not support JavaScript</b> </noscript> </head> ... 1 2 Semicolons, whitespace and case sensitive In JavaScript semicolons are optional. Use them anyway, it is more secure! Whitespaces are ignored by JavaScript, unless as part of a String (e.g. I like JavaScript) and for separating keywords, variable names, numbers and functions. JavaScript is case sensitive, that means: bgColor is not equal to bgcolor . 3 Comments 3.1 Single-line comment // e.g. to comment the meaning of a variable 3.2 Multiple-line comment /* e.g. to comment purpose and parameters of a function * Function: saySomething * Purpose: displaying a message in an alert box * Parameters: * message: the string to be displaying in the alert box * Return: The return value of this function is void * (no return value) * Side Effects: This function changes no global variables. */ 4 Variables 4.1 Variable assignment Using var outside of function is optional. Assigning variables using var inside of functions is required if (a) we want to declare a local variable and a global variable with the same name already exists.(b)If recursive functions use variables with the same name. x = 42; var x = 42; 4.2 Variable scope Variables in JavaScript have in general global scope. However, variables assigned inside of functions have function-local-scope. Take care, if you define a local variable in a function and a global variable with the same name exists, the global variable is not visible any more inside the function, no matter where you define the local variable....
View Full Document

This note was uploaded on 04/29/2010 for the course CS 5503 taught by Professor Kaylor during the Spring '10 term at W. Alabama.

Page1 / 11

javascriptcheatsheet - JavaScript cheat sheet Holmer Hemsen...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online