Author Archives: Help_adm

JavaScript For Of

The For Of Loop The JavaScript for of statement loops through the values of an iterable object. It lets you loop over iterable data structures such as Arrays, Strings, Maps, NodeLists, and more: Syntax for (variable of iterable) {  // code block to be executed} variable – For every iteration the value of the next property is assigned to the variable. Variable can… Read More »

JavaScript For In

The For In Loop The JavaScript for in statement loops through the properties of an Object: Syntax for (key in object) {  // code block to be executed} Example <!DOCTYPE html> <html> <body> <h2>JavaScript For In Loop</h2> <p>The for in statement loops through the properties of an object:</p> <p id=”demo”></p> <script> const person = {fname:”John”, lname:”Doe”, age:25}; let txt = “”; for… Read More »

JavaScript For Loop

Loops can execute a block of code a number of times. JavaScript Loops Loops are handy, if you want to run the same code over and over again, each time with a different value. Often this is the case when working with arrays: Instead of writing: <!DOCTYPE html> <html> <body> <h2>JavaScript For Loop</h2> <p id=”demo”></p>… Read More »

JavaScript Switch Statement

The switch statement is used to perform different actions based on different conditions. The JavaScript Switch Statement Use the switch statement to select one of many code blocks to be executed. Syntax switch(expression) {  case x:    // code block    break;  case y:    // code block    break;  default:    // code block} This is how it works: The switch expression is evaluated once. The value of the expression is compared with… Read More »

JavaScript if, else, and else if

Conditional statements are used to perform different actions based on different conditions. Conditional Statements Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this. In JavaScript we have the following conditional statements: Use if to specify a block of code to… Read More »

JavaScript Comparison and Logical Operators

Comparison Operators Comparison operators are used in logical statements to determine equality or difference between variables or values. Given that x = 5, the table below explains the comparison operators: Operator Description Comparing Returns == equal to x == 8x == 5x == “5” falsetruetrue === equal value and equal type x ===5x === “5” truefalse… Read More »

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

JavaScript Random

Math.random() Math.random() returns a random number between 0 (inclusive),  and 1 (exclusive): Example <!DOCTYPE html> <html> <body> <h2>JavaScript Math.random()</h2> <p>Math.random() returns a random number between 0 (included) and 1 (excluded):</p> <p id=”demo”></p> <script> document.getElementById(“demo”).innerHTML = Math.random(); </script> </body> </html> Result: JavaScript Math.random() Math.random() returns a random number between 0 (included) and 1 (excluded): 0.7717152983822737 Math.random() always returns… Read More »

JavaScript Math Object

The JavaScript Math object allows you to perform mathematical tasks on numbers. Example <!DOCTYPE html> <html> <body> <h2>JavaScript Math.PI</h2> <p>Math.PI returns the ratio of a circle’s circumference to its diameter:</p> <p id=”demo”></p> <script> document.getElementById(“demo”).innerHTML = Math.PI; </script> </body> </html> Result: JavaScript Math.PI Math.PI returns the ratio of a circle’s circumference to its diameter: 3.141592653589793 The… Read More »

JavaScript Set Date Methods

Set Date methods let you set date values (years, months, days, hours, minutes, seconds, milliseconds) for a Date Object. Set Date Methods Set Date methods are used for setting a part of a date: Method Description setDate() Set the day as a number (1-31) setFullYear() Set the year (optionally month and day) setHours() Set the… Read More »