provided, as well as a useful toString: var d = new Date(2010, 2, 1, 14, 25, 30); // 2010-Mar-01 14:25:30; // Displays '2010-3-1 14:25:30': console.log(d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds()); // Built-in toString returns something like 'Mon Mar 01 2010 14:25:30 GMT-0500 (EST)': console.log(d); Error Custom error messages can be created using the Error class: throw new Error("Something went wrong."); These can be caught by try...catch...finally blocks as described in the section on exception handling. Math The object contains various math-related constants (for example, ) and functions (for example, cosine). (Note that the object has no constructor, unlike or . All its methods are "static", that is "class" methods.) All the trigonometric functions use angles expressed in radians, not degrees or grads. Regular expression /expression/.test(string); // returns Boolean "string".search(/expression/); // returns position Number "string".replace(/expression/, replacement); // Here are some examples if (/Tom/.test("My name is Tom")) console.log("Hello Tom!"); console.log("My name is Tom".search(/Tom/)); // == 11 (letters before Tom) console.log("My name is Tom".replace(/Tom/, "John")); // == "My name is John" Character classes // \d - digit // \D - non digit // \s - space // \S - non space // \w - word char // \W - non word // [ ] - one of // [^] - one not of // - - range if (/\d/.test('0')) console.log('Digit'); if (/[0-9]/.test('6')) console.log('Digit'); if (/[13579]/.test('1')) console.log('Odd number'); if (/\S\S\s\S\S\S\S/.test('My name')) console.log('Format OK'); if (/\w\w\w/.test('Tom')) console.log('Hello Tom'); if (/[a-zA-Z]/.test('B')) console.log('Letter'); Character matching // A...Z a...z 0...9 - alphanumeric // \u0000...\uFFFF - Unicode hexadecimal // \x00...\xFF - ASCII hexadecimal // \t - tab // \n - new line // \r - CR // . - any character // | - OR if (/T.m/.test('Tom')) console.log ('Hi Tom, Tam or Tim'); if (/A|B/.test("A")) console.log ('A or B'); Repeaters // ? - 0 or 1 match // * - 0 or more // + - 1 or more // {n} - exactly n // {n,} - n or more // {0,n} - n or less // {n,m} - range n to m if (/ab?c/.test("ac")) console.log("OK"); // match: "ac", "abc" if (/ab*c/.test("ac")) console.log("OK"); // match: "ac", "abc", "abbc", "abbbc" etc. if (/ab+c/.test("abc")) console.log("OK"); // match: "abc", "abbc", "abbbc" etc. if (/ab{3}c/.test("abbbc")) console.log("OK"); // match: "abbbc" if (/ab{3,}c/.test("abbbc")) console.log("OK"); // match: "abbbc", "abbbbc", "abbbbbc" etc. if (/ab{1,3}c/.test("abc")) console.log("OK"); // match: "abc", "abbc",