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 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 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 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 Read More…


Nested if statements JavaScript | Simple example code

Nested if statements JavaScript used to get multiple possible outcomes. the if-else statement only supports two blocks but it can be used as many times as you like to increase the possible outcomes. Nested if statements JavaScript example code Nesting if statements meaning using if or if-else inside another if or else statement. let’s See Read More…


JavaScript if and 2 conditions | multiple values example code

How to check multiple values in if condition in JavaScript? Use one/both of the logical operators && and || the first is read “and”, the second “or” to check the JavaScript Two conditions in if statement. JavaScript if and 2 conditions example Let’s see complete HTML examples for Two conditions And && If you want Read More…


JavaScript increment counter number on button click | Example code

The purist way to do this would be to add event handlers to the button, to increment a counter number in JavaScript. JavaScript increment a counter examples HTML examples code with ‘Plain‘ JavaScript:- 1. Increment number variable value Create a JavaScript variable and increment that variable when press a button (without submit the form). Counterexample: Read More…


JavaScript auto increment variable | Example code

Incremental operator ++ used to increase the existing variable value by 1 (x = x + 1). Increment operators in JS programming used in For Loop, While loop, and Do While loops. ++i (Pre increment): It will increment the value of i even before assigning it to the variable i. i++ (Post-increment): The operator returns the variable Read More…