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 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 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 […]

JavaScript Sorting Arrays

The sort() method sorts an array alphabetically: Example var fruits = [“Banana”, “Orange”, “Apple”, “Mango”]; fruits.sort();        // Sorts the elements of fruits Try it Yourself » Reversing an Array The reverse() method reverses the elements in an array. You can use it to sort an array in descending order: Example var fruits = [“Banana”, “Orange”, “Apple”, “Mango”]; fruits.sort();        // First sort the elements of fruits fruits.reverse();     // Then reverse the […]

JavaScript Strings

JavaScript strings are used for storing and manipulating text. JavaScript Strings A JavaScript string is zero or more characters written inside quotes. Example var answer = “It’s alright”; var answer = “He is called ‘Johnny’”; var answer = ‘He is called “Johnny”‘; Try it Yourself » String Length The length of a string is found in the built in property length: Example […]

JavaScript Comments

JavaScript comments can be used to explain JavaScript code, and to make it more readable. JavaScript comments can also be used to prevent execution, when testing alternative code. Single Line Comments Single line comments start with //. Any text between // and the end of the line will be ignored by JavaScript (will not be […]