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 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 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 Booleans

A JavaScript Boolean represents one of two values: true or false. Boolean Values Very often, in programming, you will need a data type that can only have one of two values, like YES / NO ON / OFF TRUE / FALSE For this, JavaScript has a Boolean data type. It can only take the values true or false. The Boolean() Function You can […]

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

JavaScript Syntax

JavaScript syntax is the set of rules, how JavaScript programs are constructed: var x, y;          // How to declare variables x = 5; y = 6;      // How to assign values z = x + y;         // How to compute values JavaScript Values The JavaScript syntax defines two types of values: Fixed values and variable values. Fixed values are called literals. Variable values […]

JavaScript Statements

Example var x, y, z;    // Statement 1 x = 5;          // Statement 2 y = 6;          // Statement 3 z = x + y;      // Statement 4 Try it Yourself » JavaScript Programs A computer program is a list of “instructions” to be “executed” by a computer. In a programming language, these programming instructions are called statements. A JavaScript program is a list of programming statements. In […]

JavaScript Where To

The <script> Tag In HTML, JavaScript code must be inserted between <script> and </script> tags. Example <script> document.getElementById(“demo”).innerHTML = “My First JavaScript”; </script> Try it Yourself » Old JavaScript examples may use a type attribute: <script type=”text/javascript”>. The type attribute is not required. JavaScript is the default scripting language in HTML. JavaScript Functions and Events A JavaScript function is […]

JavaScript Introduction

This page contains some examples of what JavaScript can do. JavaScript Can Change HTML Content One of many JavaScript HTML methods is getElementById(). This example uses the method to “find” an HTML element (with id=”demo”) and changes the element content (innerHTML) to “Hello JavaScript”: document.getElementById(“demo”).innerHTML = “Hello JavaScript”; Try it Yourself » JavaScript accepts both double and single […]