JavaScript Basics: Difference between revisions
Jump to navigation
Jump to search
| Line 14: | Line 14: | ||
The following are considered false: <code>false</code>, <code>0</code>, <code>""</code>, <code>null</code>, <code>undefined</code>, <code>NaN</code>. | The following are considered false: <code>false</code>, <code>0</code>, <code>""</code>, <code>null</code>, <code>undefined</code>, <code>NaN</code>. | ||
== Arrays == | |||
Arrays are special objects. | |||
<pre> | |||
var my_array = []; // make a new array | |||
</pre> | |||
== Strings == | == Strings == | ||
Revision as of 16:47, 18 April 2015
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.
Arrays
Arrays are special objects.
var my_array = []; // make a new array
Strings
" Hello ".trim() // "Hello"
Objects
var new_object = {}; // make a new empty object
new_object.name = "Bill"; // create a property
new_object["name"] = "Bill"; // same thing
for (var key in my_object){ // iterate over an object
// do something with key
// value is my_object[key]
}