Author Archives: Help_adm

JavaScript Operators

Example Assign values to variables and add them together:<!DOCTYPE html><html><body><h2>JavaScript Operators</h2><p>x = 5, y = 2, calculate z = x + y, and display z:</p><p id=”demo”></p><script>let x = 5;let y = 2;let z = x + y;document.getElementById(“demo”).innerHTML = z;</script></body></html> Result: JavaScript Operators x = 5, y = 2, calculate z = x + y, and… Read More »

JavaScript Const

The const keyword was introduced in ES6 (2015). Variables defined with const cannot be Redeclared. Variables defined with const cannot be Reassigned. Variables defined with const have Block Scope. Cannot be Reassigned A const variable cannot be reassigned: Example <!DOCTYPE html> <html> <body> <h2>JavaScript const</h2> <p id=”demo”></p> <script> try {  const PI = 3.141592653589793;  PI = 3.14; } catch (err) {  document.getElementById(“demo”).innerHTML = err; } </script>… Read More »

JavaScript Let

The let keyword was introduced in ES6 (2015). Variables defined with let cannot be Redeclared. Variables defined with let must be Declared before use. Variables defined with let have Block Scope. Cannot be Redeclared Variables defined with let cannot be redeclared. You cannot accidentally redeclare a variable. With let you can not do this: Example let x = “John Doe”; let x = 0; // SyntaxError: ‘x’ has already been declared With var you can:… Read More »

JavaScript Variables

4 Ways to Declare a JavaScript Variable: Using var Using let Using const Using nothing What are Variables? Variables are containers for storing data (storing data values). In this example, x, y, and z, are variables, declared with the var keyword: Example <!DOCTYPE html> <html> <body> <h1>JavaScript Variables</h1> <p>In this example, x, y, and z are variables.</p> <p id=”demo”></p> <script> var x =… Read More »

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 executed). This example… Read More »

JavaScript Syntax

JavaScript syntax is the set of rules, how JavaScript programs are constructed:// How to create variables:var x;let y; // How to use variables:x = 5;y = 6;let z = x + y; JavaScript Values The JavaScript syntax defines two types of values: Fixed values Variable values Fixed values are called Literals. Variable values are called Variables. JavaScript Literals The two most important syntax… Read More »

JavaScript Statements

Example <!DOCTYPE html> <html> <body> <h2>JavaScript Statements</h2> <p>A <b>JavaScript program</b> is a list of <b>statements</b> to be executed by a computer.</p> <p id=”demo”></p> <script> let x, y, z;  // Statement 1 x = 5;        // Statement 2 y = 6;        // Statement 3 z = x + y;  … Read More »

JavaScript Display Output Possibilities

JavaScript Display Possibilities JavaScript can “display” data in different ways: Writing into an HTML element, using innerHTML. Writing into the HTML output using document.write(). Writing into an alert box, using window.alert(). Writing into the browser console, using console.log(). Using innerHTML To access an HTML element, JavaScript can use the document.getElementById(id) method. The id attribute defines the HTML element. The innerHTML property defines the HTML content:… Read More »

JavaScript Where To Use?

The <script> Tag In HTML, JavaScript code is inserted between <script> and </script> tags. Example <!DOCTYPE html> <html> <body> <h2>JavaScript in Body</h2> <p id=”demo”></p> <script> document.getElementById(“demo”).innerHTML = “My First JavaScript”; </script> </body> </html> Result: JavaScript in Body My First JavaScript Old JavaScript examples may use a type attribute: <script type=”text/javascript”>.The type attribute is not required. JavaScript is the default… Read More »

Introduction Of Java Script

JavaScript is the world’s most popular programming language. JavaScript is the programming language of the Web. JavaScript is easy to learn. This tutorial will teach you JavaScript from basic to advanced. JavaScript Can Change HTML Content One of many JavaScript HTML methods is getElementById(). The example below “finds” an HTML element (with id=”demo”), and changes the… Read More »