JavaScript Random

JavaScript Random numbers are created with Math.random() function. It is mentioned below: Random Function Creating a proper random function to use for all random integer purposes can be a good idea. The following JavaScript function always returns a random number between min (included) and max (excluded): Output: The following JavaScript function always returns a random … Read more

JavaScript Conditional Statements

JavaScript Conditional statements are used to control some actions based on various conditions. For different decisions, we want to perform different actions. The JavaScript conditional statements can be used in code for this purpose. If the condition is true it performed an action or if the condition is false it performed another action. JavaScript Conditional … Read more

JavaScript Output

JavaScript doesn’t have any functions for printing or outputting. JavaScript output means different ways to display the given code output. There are many ways to write the output in JavaScript. These methods are as follows: JavaScript Output – innerHTML The document.getElementById(id) method is used to access an HTML element. The id attribute is used to … Read more

JavaScript Break and Continue

The JavaScript break and continue statements are very important. The break statement is used to terminate or jump out of a loop and the continue statement is used to skip one iteration or jump over one iteration in the loop. Following are explanations of JavaScript Break and Continue with an example: The Break Statement The … Read more

Sorting arrays using for loops in JavaScript

It is possible to sort arrays in ascending/descending order using the for loop JavaScript as well as by using JavaScript Sort Method. Multiple or nested loos are used for sorting arrays using for loops in JavaScript or using while loop. The example sorting an array of number using for loops is given below. Sorting arrays … Read more

JavaScript Boolean

The JavaScript Boolean represents a boolean primitive type of true or false values. It is very helpful in controlling workflow in conditional statements. In many situations we might have only one of two values: The Boolean() function can be used to find out if a variable or an expression is true: An expression Boolean value is a basis for all JavaScript … Read more

JavaScript Loops

JavaScript loops are used to execute a block of code many times. Loops are very helpful if we want to run the same code, again and again, each time with a different value. Instead of writing a print statement many times, we can apply a loop and execute it as many as we want. Because … Read more

JavaScript Comparison and Logical Operators

The JavaScript comparison and Logical operators are important topics in JavaScript. Comparison operators compare two values and give back a Boolean value: either true or false. Comparison operators can be used in conditional statements or in loop statements to compare values and take action depending on the result. JavaScript Comparison Operators To determine the equality or difference between … Read more

JavaScript Switch Statement

The switch statement can be used to perform multiple if statement functionality. It is used to perform various actions based on various conditions. The switch statement is used to select one of many code blocks to be executed. Its syntax is given below: Switch Statement – Flowchart The flowchart of the switch statement is given … Read more