JavaScript

Window

The window object represents the browser window or frame and also inherits all of the global JavaScript core properties

History

The history object represents the browsers URL history. Methods are back(), forward() and go().

// go back twice
history.go(-2);

Location

The location object represents the document URL.

// reload the current document
location.reload();

// current location properties

Navigator

The navigator object contains several properties with info about the browser.

// information about the browser
navigator.userAgent;

// current navigator.userAgent properties

Screen

The screen object contains properties with info about the display.

// show information about screen size
alert(screen.width + 'x' + screen.height);

// current screen properties

Document

The Document object represents the root node of HTML, XHTML and XML documents. The nodes of every document are organized in a tree structure, called the DOM tree. Objects in the DOM tree may be addressed and manipulated by using methods on the objects.

Document object reference page


Global Objects

Array
An array is an ordered collection of elements that can be selected by indices. JS Bin
var ballsArray = ["Titleist", "Callaway", "Srixon"];
var scoresArray = [80, 82, 79];
Boolean
A boolean object is an object wrapper around the fundamental boolean datatype value (true or false).
var bool = false;
alert('bool is ' + bool);
Date
A date object is used to work with dates and times. JS Bin
// new Date object
var d = new Date();
d.getFullYear();

// date string
var s = Date();
console.log(s);
Error
An error object contains information to describe JavaScript errors. JS Bin
try {
    throw new Error("Oh Snap");
} catch (e) {
    console.log(e.name + ": " + e.message);
}
JSON
A JSON (JavaScript Object Notation) object is used for converting values to JSON and values from JSON.
var json = '{"result":true,"count":1}',
obj = JSON.parse(json);
console.log(obj.count);
console.log(JSON.stringify(obj));
Math
A math object is used for mathematical functions and constants.
// shows 10
alert(Math.floor(10.6));
Number
A number object is used for numeric functions and constants.
// create number object
var num = new Number(10);
RegExp
A RegExp object is to create regular expressions for pattern matching. JS Bin
// regular expression defining 5 digits
var fiveDigitPattern=/^\d{5}$/;
var digits = "12345";
alert(digits.search(fiveDigitPattern)== -1? false:true );
String
A string object is used for string functions and constants.
// create string object
var str = new String("Hello world");
//or
var str = "Hello world";
Functions & Properties
decodeURI
A function that returns a decoded URI by replacing each UTF-8 escape sequence with it’s respective characters. JS Bin
console.log(decodeURI('~!@#$%25%5E&*()=+%5B%5D%7B%7D%5C;:\'%22,/?'));
decodeURIComponent
A function that returns a decoded URI component by replacing each UTF-8 escape sequence with it’s respective characters. JS Bin
console.log(decodeURIComponent('~!%40%23%24%25%5E%26*()%3D%2B%5B%5D%7B%7D%5C%3B%3A\'%22%2C%2F%3F'));
encodeURI
A function that returns an encoded URI by replacing all special characters with their respective UTF-8 escape sequences. JS Bin
console.log(encodeURI('~!@#$%^&*()=+[]{}\\;:\'",/?'));
encodeURIComponent
A function that returns an encoded URI component by replacing all special characters with their respective UTF-8 escape sequences. JS Bin
console.log(encodeURIComponent('~!@#$%^&*()=+[]{}\\;:\'",/?'));
eval
A function that evaluates a JavaScript expression.
var x = 5;
var str = "if (x == 5) {console.log('z is 42'); z = 42;} else z = 0; ";
eval(str);
infinity
A property that represents a number that is greater than any other number, including itself.
var x = Math.pow(2, 1024);
console.log(x);
    
isFinite
A function that returns true if the value exceeds the lower limit 5e-324 (Number.MIN_VALUE) or the upper limit 1.7976931348623157e+308 (Number.MAX_VALUE), false otherwise.
var x = isFinite(Math.sqrt(-4));
console.log(x);
var y = isFinite(50);
console.log(y);
isNaN
A function that returns true if the value is a number, false otherwise.
console.log(isNaN(50));
console.log(isNaN('foo'));
NaN
A property that represents a NaN (Not a Number) value.
console.log(Number('foo'));
parseFloat
A function that returns the float value of a variable.
// both return 1.505
console.log(parseFloat('1.5050'));
console.log(parseFloat('0.015050E+2'));
parseInt
A function that returns the integer value of a variable.
// return 50
console.log(parseInt('50');
undefined
A property that represents a variable that has not been declared or initialised. JS Bin
foo; // throws an error, foo is not defined
var foo; // foo is uninitialised

if (typeof foo === 'undefined') {
    // foo is undefined
}

Resources

Loading Disqus Comments ...
Loading Facebook Comments ...