URL Info Access | Accessing a URL via web browser JavaScript

JavaScript provides you with many methods to retrieve and change the current URL, which is displayed in the browser’s address bar. All these methods use the Location object, which is a property of the Window object. You can create a new Location object that has the current URL as follows: Basic URL Structure protocol: Specifies Read More…



JavaScript set the label text | Simple example code

Use the innerHTML property to change or set the text inside the label in JavaScript. The innerHTML property sets or returns the HTML content of an element. document.getElementById(‘label’).InnerHTML = ‘your text goes here’; JavaScript set label text Example You can change or set the text of a label using JavaScript. Here is the HTML example Read More…


Window Variable JavaScript | Declare global variables inside a function

Window Variable means that the variable is being declared at the global scope In JavaScript. Window Variable is used to declare JavaScript global variables inside the function. However, it’s not recommended to create or declarer Global variables generally and it should be avoided. A better way to define variables within the scope of functions. Window Read More…


JavaScript global variable | Example code

Variables don’t have limited scope to use by only a single function and defined outside of functions called global variables in JavaScript. A global variable can be defined anywhere in your JavaScript code and can be accessed from any function or scripts. JavaScript global variable Example code HTML example code:- Output: What is the JavaScript Read More…


Scope of variables in JavaScript | Simple example code

Scope of variables in JavaScript only has two types Global Variables and Local Variables. Note: In JavaScript, objects and functions are also variables. Scope of variables in JavaScript and Examples Let’s see HTML example code for both type of scope and understand the use and different of it. Global Scope A variables are outside of Read More…


Ternary operator multiple conditions JavaScript | Example code

Ternary operator more than one condition is possible with nesting it. Let’s see example for that in this tutorial. Example of Ternary operator multiple conditions JavaScript HTML example code for If mark -> 1 then result = A If mark -> 2 then result = B else result = C Output: JS Ternary functions with Read More…


JavaScript conditional operator | Example code

JavaScript conditional operator is assigned a value to a variable based on some condition. It’s the only JavaScript operator that takes three operands. It also called a ternary operator. Syntax of conditional operator in JS. JavaScript conditional operator Example Let’s see simple HTML example code for a given condition – If the value is above Read More…


JavaScript addition, subtraction, multiplication, division | Simple Examples

Addition, subtraction, multiplication, and division are basic Arithmetic operations in JavaScript. Addition Code: The addition operator (+) adds numbers: Subtraction code: The subtraction operator (-) subtracts numbers. Multiplication Code: The multiplication operator (*) multiplies numbers. Division Code: The division operator (/) divides numbers. JavaScript addition, subtraction, multiplication, division Examples HTML complete example code for all Read More…


JavaScript multiple if statements not Good | Alternative Switch Case

Using multiple if statements or if else statements, look very bulky in JavaScript or other programming languages. Multiple if statements and then else JavaScript Example If condition matches then inside code execute of if and else. But if the condition matched the last if statement then else will not be executed. Output: An alternative to Read More…