Web Development Articles - Page 499 of 1049

object.is() in equality comparison JavaScript

AmitDiwan
Updated on 17-Jul-2020 07:25:56

117 Views

The object.is() method introduced in ES6 as a way to compare two values. These two values can either be primitives or objects. It does a little better comparison than == and ===.Following is the code for object.is() in equality comparison −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: blueviolet;    } Object.is() equality comparsion Click here Click on the above button to compare objects ... Read More

Event bubbling vs event capturing in JavaScript?

AmitDiwan
Updated on 17-Jul-2020 07:23:13

977 Views

Event Bubbling − Whenever an event happens on an element, the event handlers will first run on it and then on its parent and finally all the way up to its other ancestors.Event Capturing − It is the reverse of the event bubbling and here the event starts from the parent element and then to its child element.Following is the code for event bubbling vs event capturing in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px; ... Read More

Undefined in JavaScript

AmitDiwan
Updated on 17-Jul-2020 07:19:59

296 Views

The JavaScript undefined property specifies if a variable has been declared or assigned a value yet.Following is the code implementing the JavaScript undefined property −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;       color: red;    } JavaScript undefined property CLICK HERE CLICK the above button to know if variable age has been defined or not    let sampleEle = document.querySelector(".sample");    let age;   ... Read More

Template strings in JavaScript.

AmitDiwan
Updated on 17-Jul-2020 07:16:35

534 Views

Template were introduced in ES6 to allow embed expressions inside a string. Instead of ‘’ or “” quotation marks they use the backticks (``). They offer a much better way of string interpolation and expressions can be embedded in a way like ${a+b}. It offers a much nicer syntax than the + operator.Following is the code for template strings in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;       ... Read More

Escape characters in JavaScript

AmitDiwan
Updated on 17-Jul-2020 07:12:58

9K+ Views

Escape characters are characters that can be interpreted in some alternate way then what we intended to. To print these characters as it is, include backslash ‘\’ in front of them. Following are the escape characters in JavaScript −CodeResult\bBackspace\fForm FeedNew Line\rCarriage Return\tHorizontal Tabulator\vVertical Tabulator\'Single quote\"Double quote\BackslashFollowing is the code implement escape character Backslash in javaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;    } Escape characters in JavaScript ... Read More

Default exports vs Named exports in JavaScript

AmitDiwan
Updated on 16-Aug-2023 16:35:06

964 Views

In this article, we will learn the difference between default exports and named exports in javascript, and how we can use them to effectively organize our code structure. In javascript, we can use default exports and named exports so as to have separate files or modules for separate pieces of code. This helps in enhancing code readability and tree shaking to a great extent. Default exports Named exports A default export allows us to export a single value or function as the default export of a module. A named export allows us to export multiple values ... Read More

Arrays vs Set in JavaScript.

Alshifa Hasnain
Updated on 29-Mar-2025 02:56:35

2K+ Views

In this article, we will learn about the difference between an array and a set in JavaScript. Arrays are used to store ordered collections of elements, whereas in Sets, we can store only unique values. What is an Array?  An Array is an ordered, indexed collection of values in JavaScript. It allows duplicate values and provides various built-in methods to manipulate elements. Syntax let numbers= [1, 2, 3, 4, 5]; What is a Set? A Set is an unordered collection of unique values in JavaScript. Unlike arrays, a Set does not allow duplicate values. Syntax let numbers= new Set([1, 2, ... Read More

How to convert Array to Set in JavaScript?

AmitDiwan
Updated on 16-Aug-2023 15:33:12

747 Views

This tutorial will teach you how to eliminate duplicate values from an array of items in Javascript by converting an array to a set. When storing distinct values from a collection of data in javascript, we can utilise the Set data structure to get rid of duplicate values. When we wish to eliminate duplicates from our data or take advantage of the special features offered by Sets data structure, converting an array to a Set can be helpful. Let’s look at some of the examples and methods to understand the concept better − Example 1 - Using the Set Constructor ... Read More

What are Promises in JavaScript?

AmitDiwan
Updated on 16-Aug-2023 16:04:39

881 Views

Promises, in JavaScript, can be used to simplify asynchronous programming, making it easier to handle asynchronous operations like I/O operations or communicate with an external system or machine. Promises are objects that represent the eventual completion or failure of an asynchronous operation and its resulting value. They provide an easy way to deal with asynchronous code, allowing us to write cleaner and more readable code. Here we will discover what are promises in javascript and how to use them to incorporate asynchronous programming behaviour into our control flow, in this tutorial. A promise has 3 states − Pending − ... Read More

How to use named arguments in JavaScript functions?

AmitDiwan
Updated on 16-Aug-2023 15:58:15

2K+ Views

In this article, we will learn how to use named arguments in javascript, and how we can use it to significantly enhance code readability and maintainability. Javascript allows us to use named arguments, which eliminate the need for the order of parameters to matter during function execution. We may then access the arguments by name inside the function definitions. Let’s look at some of the examples and methods to understand the concept better − Example 1 - Passing Objects as Arguments We can pass an object as an argument to the function to achieve named−argument functionality. This uses the ... Read More

Advertisements