Monthly Archives: August 2022

JavaScript Type Conversion

Converting Strings to Numbers Converting Numbers to Strings Converting Dates to Numbers Converting Numbers to Dates Converting Booleans to Numbers Converting Numbers to Booleans JavaScript Type Conversion JavaScript variables can be converted to a new variable and another data type: By the use of a JavaScript function Automatically by JavaScript itself Converting Strings to Numbers The… Read More »

JavaScript typeof

In JavaScript there are 5 different data types that can contain values: string number boolean object function There are 6 types of objects: Object Date Array String Number Boolean And 2 data types that cannot contain values: null undefined The typeof Operator You can use the typeof operator to find the data type of a JavaScript variable.… Read More »

JavaScript Maps

A Map holds key-value pairs where the keys can be any datatype. A Map remembers the original insertion order of the keys. Essential Map Methods Method Description new Map() Creates a new Map set() Sets the value for a key in a Map get() Gets the value for a key in a Map delete() Removes… Read More »

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 »