2006/01/13

[JavaScript] Quick cheatsheet

comments:
// comments
/* comments */

keywords:
break, do, if, switch, typeof, case, else, in, this , var, catch, false, instanceof, throw, void, continue, finally, new, true, while, default, for, null, try, with, delete, function, return

reserved words:
abstract, enum, int, short, boolean, export, interface, static, byte, extends, long, super, char, final, native, synchronized, class, float, package, throws, const, goto, private, transient, debugger, implements, protected, volatile, double, import, public

variables:
var variableName = assignedValue;

objects:
var o = new Object();
o.x = 1; o.y=2;
o["x"]=1; o["y"]=2;

arrays:
var a = new Array();
var a = new Array(10);
var a = new Array(1,2,3,4,5);
var a = [1,2,3,4,5];

functions:
function abc() {
// methods
}

JavaScript in HTML:
<script language="javascript">
//code
</script>

<script language="javascript" type="text/javascript" src="source.js"></script>

Event handlers:
<tag onclick="alert('Hello');">

沒有留言: