JavaScript String Reference

JavaScript Strings A JavaScript string stores a series of characters like “John Doe”. A string can be any text inside double or single quotes: var carname = “Volvo XC60”; var carname = ‘Volvo XC60’; String indexes are zero-based: The first character is in position 0, the second in 1, and so on. For a tutorial about Strings, read our JavaScript […]

JavaScript Statements Reference

JavaScript Statements In HTML, JavaScript statements are “instructions” to be “executed” by the web browser. This statement tells the browser to write “Hello Dolly.” inside an HTML element with id=”demo”: Example document.getElementById(“demo”).innerHTML = “Hello Dolly.”; Try it Yourself » For a tutorial about Statements, read our JavaScript Statements Tutorial. JavaScript Statement Identifiers JavaScript statements often start with a statement […]

JavaScript RegExp Reference

RegExp Object A regular expression is an object that describes a pattern of characters. Regular expressions are used to perform pattern-matching and “search-and-replace” functions on text. Syntax /pattern/modifiers;   Example var patt = /dwfaisalabad/i Example explained: /dwfaisalabad/i  is a regular expression. dwfaisalabad is a pattern (to be used in a search). i  is a modifier […]

JavaScript Operators Reference

JavaScript operators are used to assign values, compare values, perform arithmetic operations, and more. JavaScript Arithmetic Operators Arithmetic operators are used to perform arithmetic between variables and/or values. Given that y = 5, the table below explains the arithmetic operators: Operator Description Example Result in y Result in x Try it + Addition x = y […]

JavaScript Number Reference

JavaScript Numbers JavaScript has only one type of number. Numbers can be written with, or without, decimals: Example var x = 3.14;     // A number with decimals var y = 34;       // A number without decimals Extra large or extra small numbers can be written with scientific (exponent) notation: Example var x = 123e5;    // 12300000 var y = 123e-5;   // 0.00123 For a tutorial about JavaScript […]

JavaScript Math Reference

Math Object The Math object allows you to perform mathematical tasks. Math is not a constructor. All properties/methods of Math can be called by using Math as an object, without creating it. Syntax var x = Math.PI;            // Returns PI var y = Math.sqrt(16);      // Returns the square root of 16 For a tutorial about the Math object, read […]

JavaScript JSON Reference

JSON (JavaScript Object Notation) JSON is a format for storing and transporting data. JSON is text, and text can be transported anywhere, and read by any programming language. JavaScript Objects can be converted into JSON, and JSON can be converted back into JavaScript Objects. This way we can work with the data as JavaScript objects, with no complicated […]

JavaScript Global Reference

The JavaScript global properties and functions can be used with all the built-in JavaScript objects. JavaScript Global Properties Property Description Infinity A numeric value that represents positive/negative infinity NaN The NaN property represents “Not-a-Number” value. This property indicates that a value is not a legal number. The NaN property is the same as the Number.Nan […]

JavaScript Error Reference

Error Object The Error object provides error information when an error occurs. Example In this example we have written “alert” as “adddlert” to deliberately produce an error. Return the error name and a description of the error: try { adddlert(“Welcome”); } catch(err) { document.getElementById(“demo”).innerHTML = err.name + “<br>” + err.message; } Try it Yourself » For a tutorial about JavaScript […]

JavaScript Boolean Reference

JavaScript Booleans JavaScript booleans can have one of two values: true or false. The Boolean() Function You can use the Boolean() function to find out if an expression is true: Example Boolean(10 > 9)       // returns true Try it Yourself » Or even easier: Example (10 > 9)              // also returns true 10 > 9                // also returns true Try it Yourself » For […]

JavaScript Array Reference

Array Object The Array object is used to store multiple values in a single variable: var cars = [“Saab”, “Volvo”, “BMW”]; Array indexes are zero-based: The first element in the array is 0, the second is 1, and so on. For a tutorial about Arrays, read our JavaScript Array Tutorial. Array Properties Property Description constructor Returns the function that […]

JavaScript Date Reference

Date Object The Date object is used to work with dates and times. Date objects are created with new Date(). There are four ways of instantiating a date: var d = new Date(); var d = new Date(milliseconds); var d = new Date(dateString); var d = new Date(year, month, day, hours, minutes, seconds, milliseconds); For a tutorial about date and times, read our JavaScript Date Tutorial. Date Object Properties Property Description constructor Returns the function […]