How to load js asynchronously?
<script src="script.js" type="text/javascript" async></script>
How to load js async in order?
<script src="script.js" type="text/javascript" defer></script>
How to popup a message?
How to convert a value to bool explicitly?
var boolValue = Boolean(otherValue);
var boolValue = !!(otherValue);
What are the weird behaviors in js?
var arr = [];
arr[0] = "0"; // arr.length is 1
arr[5] = "1"; // arr.length is 6
What are the methods in array?
arr.push() // Add to end
arr.pop() // Delete from end
arr.unshift() // Add to front
arr.shift() // Delete from front
arr.sort() // Sort
arr.reverse() // Reverse
arr.join() // Join arr into string
How to use dict?
var obj = new Object;
obj.value = "Value";
// Can refer to this property in a couple of ways:
What are the methods in string?
s.substring() // Get substring
s.indexOf() // Get index of that char
s[0] // Get char of that index (Fails in IE)
s.charAt() // Get char of that index
s.length // Get length
s.split() // Split string into arrays
How to parse?
var n1 = parseInt("42 is the answer."); // 42
var n2 = parseFloat("booyah"); // NaN
What is the "window" object?
Top-level obj in DOM. All global code and vars become part of window obj properties: document, history, location, name
Methods include: open, close
What is the "document" object?
Current webpage & elements inside it
What is the "Screen" object?
Provides info about client's display screen
Screen: What is visible to you, device screen.
Window: Browser window & contains non-doc elements, e.g. scrollbars, nagivation bars, etc.
Document: Can extend beyond that (especially vertically)
What are the types of DOM nodes?
Element nodes: HTML tags
Text nodes: Text in a block element
Comment nodes: like <!-- comment -->
White space nodes
How to add a child?
var p = document.createElement("p");
p.innerHTML = "A paragraph.";
What is "Unobtrusive JS"?
using DOM to attach & execute all JS functions.
Allows separation of content(HTML), style (CSS), & behavior (JS)
How to wait for HTML DOM to load before running JS?
// This will run once pate has finish loading
function functionName() {
element.event = fuctionName;
window.onload = functionName; // Global code
How to declare anonymous functions?
function (parameter) {
How to refer to current object?
How to set global vars?
What is local storage?
With local storage, web applications can store data locally within the user's browser.
How to use local storage?
localStorage.setItem(param1, param2)

How to init local storage?
if (localStorage.value == null) localStorage.value = 0;
Name Description
document Current HTML page & its content
history List of pages user has visited
location URL of current HTML page
navigator Info about web browser using
screen Info about scrren area (Viewport) occupied by browser
window Browser window