Found 10710 Articles for Web Development

What is difference between Microtask Queue and Callback Queue in asynchronous JavaScript?

Imran Alam
Updated on 01-Jul-2022 08:41:46

3K+ Views

In asynchronous JavaScript, there are two ways to schedule tasks – microtask queue and callback queue. Both queues are handled differently by the JavaScript engine.Microtask QueueA Microtask queue is a queue of tasks that are executed after the current task. The microtask queue is handled by the JavaScript engine before it moves on to the next task in the callback queue.ExampleHere’s an example of how microtask queue works −    Examples               console.log('start');         setTimeout(function() {          console.log('setTimeout');       }, 0);   ... Read More

How to remove elements from an array until the passed function returns true in JavaScript?

Imran Alam
Updated on 01-Jul-2022 08:33:48

369 Views

In JavaScript, there are various ways to remove elements from an array until the passed function returns true. In this tutorial, we are going to look at 3 methods in detail.Using Array.prototype.filter()The Array.prototype.filter() method can be used to remove elements from an array until the passed function returns true. Please refer to the Array filter() method for more details.Example 1The following code shows how to use this method −    Examples                   var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];       function ... Read More

How to check if a value is object-like in JavaScript?

Imran Alam
Updated on 24-Jun-2022 08:24:55

89 Views

In JavaScript, an object-like value is a value that is not a primitive value and is not undefined. An object-like value is any value that is not a primitive value, including functions, arrays, and objects. There are different methods for checking if a value is objectlike in JavaScript. In this article, we are going to look at 3 methods for checking if a value is object-like in JavaScript.Using the typeof OperatorThe typeof operator is a built-in operator in JavaScript that is used to check the type of a value. The typeof operator returns a string that is the type of ... Read More

How to Create a Currency Converter in JavaScript?

Imran Alam
Updated on 24-Jun-2022 08:33:21

8K+ Views

In this tutorial, we will be discussing how to create a currency converter in JavaScript. We will be discussing the various steps involved in creating such a converter.What is a currency converter?A currency converter is a tool that helps you convert one currency to another. For example, if you are from the United States and you are traveling to Europe, you will need to use a currency converter to convert your US dollars into Euros.Why use JavaScript to create a currency converter?JavaScript is a versatile programming language that can be used to create a wide variety of applications, including web-based ... Read More

How to create a moving div using JavaScript?

Imran Alam
Updated on 24-Jun-2022 07:50:52

11K+ Views

A moving div is a web page element that can be caused to move across the screen, or change position on the screen, automatically. The position is changed by adjusting the left and top style properties. Creating a moving div using JavaScript is a relatively simple task. All that is required is a little bit of HTML, CSS, and JavaScript code. In this tutorial, we will go over how to create a moving div using JavaScript.HTML CodeThe first thing we need is some HTML code. We will create a div with an id of "movingDiv". Inside of this div, we ... Read More

JavaScript: How to remove the key-value pairs corresponding to the given keys from an object?

Imran Alam
Updated on 24-Jun-2022 07:40:03

11K+ Views

In JavaScript, objects can be created to store data as key-value pairs. The data in an object can be accessed using the dot notation (obj.key) or the bracket notation (obj["key"]). See the below example −let obj = { key1: "value1", key2: "value2", key3: "value" };We can remove the key-value pairs corresponding to the given keys from an object but in this tutorial, we are going to look at 3 methods.Using the delete operatorThe delete operator is used to delete a property of an object. The delete operator will not delete the variable itself, but only the value of the variable.ExampleSee ... Read More

How to find the sum of all elements of a given array in JavaScript?

Imran Alam
Updated on 23-Jun-2022 13:09:06

800 Views

In programming, it is often necessary to find the sum of all elements in an array. There are many ways to do this in JavaScript. In this tutorial, we are going to look at some of the ways to find the sum of all elements in an array.Using the for loopFinding the sum of all elements in an array is a very common operation in JavaScript, and the for loop is the easiest way to do it. If you are working with arrays in JavaScript, make sure to take advantage of the for loop to find the sum of all ... Read More

How to use the debugger keyword in JavaScript?

Mayank Agarwal
Updated on 28-Apr-2022 14:31:01

574 Views

Whenever an unexpected occurrence takes place in a JavaScript code, we need to debug it to check the cause. Debugging is a very important aspect of programming that lets you determine why a system or application behaves abnormally. It is a process of testing multiple times with different inputs and finding errors to reduce bugs from computer programs.In this article, we will be exploring the debugger keyword in JavaScript and how to use them. The debugger keyword in JavaScript is a common keyword used in debugging processes and variable details. In JavaScript whenever the debugger keyword is turned ON, it ... Read More

How to use setTimeout() function in JavaScript?

Mayank Agarwal
Updated on 28-Apr-2022 14:22:15

4K+ Views

The setTimeout() function is provided by the window object, which calls the specified JavaScript function after the specified time only. This function will be called just once after waiting for the timeout set by the user.It is similar to an alarm or reminder functionality. In the same way, we set up the timeout for the desired time period after which this function is called. This method is used where we are required to add a delay in the execution of a function. This method can also be used for animations or DOM manipulations in JQuert.The input set up in the ... Read More

What is a typical use case for JavaScript anonymous functions?

Mayank Agarwal
Updated on 28-Apr-2022 13:48:59

401 Views

In this article, we are going to explore the Anonymous functions in JavaScript and also learn about their use cases. An anonymous function is a special type of function that does not have any name associated with it.In JavaScript, we normally use the function () keyword before defining any function in JavaScript. However, in anonymous functions in JavaScript, we only use the keyword function for defining the function without any supported name.An anonymous function cannot be accessed after it is created, it can only be accessed by a variable that is stored in the function as the value. An anonymous ... Read More

Advertisements