Category Archives: Java Script

JavaScript Sets

A JavaScript Set is a collection of unique values. Each value can only occur once in a Set. Essential Set Methods Method Description new Set() Creates a new Set add() Adds a new element to the Set delete() Removes an element from a Set has() Returns true if a value exists in the Set forEach()… Read More »

JavaScript Iterables

Iterables are iterable objects (like Arrays). Iterables can be accessed with simple and efficient code. Iterables can be iterated over with for..of loops The For Of Loop The JavaScript for..of statement loops through the elements of an iterable object. Syntax for (variable of iterable) {  // code block to be executed} Iterating Iterating is easy to understand. It simply means looping over… Read More »

JavaScript While Loop

Loops can execute a block of code as long as a specified condition is true. The While Loop The while loop loops through a block of code as long as a specified condition is true. Syntax while (condition) {  // code block to be executed} Example In the following example, the code in the loop will run, over and… Read More »

JavaScript Break and Continue

The break statement “jumps out” of a loop. The continue statement “jumps over” one iteration in the loop. The Break Statement You have already seen the break statement used in an earlier chapter of this tutorial. It was used to “jump out” of a switch() statement. The break statement can also be used to jump out of a loop: Example <!DOCTYPE html> <html> <body> <h2>JavaScript… Read More »

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 »