JavaScript Basics

From Wiki
Revision as of 16:44, 18 April 2015 by Scott (talk | contribs) (Types)
Jump to navigation Jump to search

Link to external Javscript file

<head>
	<title>Test</title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<script src="spectra.js" type="text/javascript" ></script>
</head>

Types

The built-in types are string, number, boolean, null, undefined, object.

Use typeof some_var to get the type.

The following are considered false: false, 0, "", null, undefined, NaN.

Strings

"  Hello  ".trim()      // "Hello"

Objects

for (var key in my_object){
    // do something with key
    // value is my_object[key]
}