The JavaScript Arithmetic Operators

Performing mathematical operations and calculations is a common task in programming languages. In JavaScript, there are several operators available to work with numbers. Addition (+) The addition operator (+) is used to add two numbers together. It can also be used for string concatenation. const three = 1 + 2 const four = three + 1 const three = 1 + 2 three + 1 // 4 'three' + 1 // "three1" Subtraction (-) The subtraction operator (-) is used to subtract one number from another....

The JavaScript Cookbook: A Collection of Useful How-Tos

Welcome to the JavaScript Cookbook, a compilation of helpful articles that provide step-by-step instructions on how to perform common tasks in JavaScript. Whether you’re a beginner or an experienced developer, you’ll find practical solutions to enhance your JavaScript skills. Note: This document is continuously updated with new content, ensuring that you have access to a wealth of valuable how-tos. Strings How to Uppercase the First Letter of a String in JavaScript: Learn how to capitalize the first letter of a string using JavaScript....

The JavaScript for...of loop: A concise and versatile looping technique

The for...of loop is a powerful and concise way to iterate over elements in JavaScript. It combines the ease of use of forEach loops with the added flexibility to break out of the loop whenever necessary. The syntax for the for...of loop is as follows: const list = ['a', 'b', 'c']; for (const item of list) { console.log(item); } With this loop, you can easily iterate over each element in the list array and perform any desired actions....

The JavaScript Global Object: Explained and Demystified

The JavaScript global object is a collection of properties, functions, and objects that can be accessed globally without the need for a specific namespace. In this blog post, we will delve into the details of the global object and explore its various components. Properties: Infinity: Represents the value infinity in JavaScript. It can be positive (Infinity) or negative (-Infinity). NaN (Not a Number): Used to represent an invalid numeric operation. It is returned when performing operations such as zero divided by zero or invalid parseInt() operations....

The JavaScript Glossary: A Guide to Frontend Development Terminology

In frontend development, there are several terms that may be unfamiliar to you. This glossary provides explanations of these terms to help you better understand JavaScript and frontend development concepts. Let’s dive in! Terms Asynchronous Asynchronous code allows you to initiate a task, forget about it, and receive the result when it’s ready, without having to wait for it. An example is an AJAX call, where you can continue with other tasks while waiting for the response....

The JavaScript if/else conditional: A Guide

Learn the basics of using the JavaScript if conditional in your code. An if statement is a powerful tool in JavaScript that allows you to control the flow of your program based on the evaluation of an expression. By using conditionals, you can make your program take different paths depending on certain conditions. Let’s start with a simple example that always executes: if (true) { // code to be executed } In this case, the code inside the if block will always run because the expression true evaluates to true....

The JavaScript Math Library: A Comprehensive Guide

The Math object in JavaScript is a powerful tool for performing various mathematical operations. This tutorial will provide an overview of the Math object and its functions. Constants The Math object contains several constants that are commonly used in mathematical calculations. These constants include: Math.E: The base of the natural logarithm, approximately equal to 2.71828. Math.LN10: The natural logarithm of 10. Math.LN2: The natural logarithm of 2. Math.LOG10E: The base 10 logarithm of e....

The JavaScript Spread Operator: A Comprehensive Guide

In JavaScript, the spread operator ... allows you to expand arrays, objects, and strings. Understanding how to utilize this operator can significantly enhance your coding capabilities. Let’s explore its various applications and examples. Expanding Arrays To create a new array by expanding an existing one, you can use the spread operator. Take the following array a as an example: const a = [1, 2, 3]; Using the spread operator, you can easily create a new array b by appending additional elements:...

The JavaScript String match() Method

Learn about the match() method in JavaScript for strings. The match() method is used to search for a specified regular expression pattern inside a string. It returns an array of all the matches found or null if no matches are found. Here are some examples of using the match() method: Example 1: 'Hi Flavio'.match(/avio/) // Output: Array [ 'avio' ] Example 2: 'Test 123123329'.match(/\d+/) // Output: Array [ "123123329" ] Example 3:...

The JavaScript toLocaleString() Method: A Guide

In JavaScript, the toLocaleString() method allows you to format a number based on a specific locale. By default, the method uses US English as the locale. However, you can pass a locale as the first parameter to format the number accordingly. Here’s an example using the default locale: new Number(21.2).toLocaleString(); // 21.2 If we want to format the number for a different locale, we can pass the locale as the first parameter....