Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Web Development Articles
Page 148 of 801
Explain the Scope and Scope Chain in JavaScript
In JavaScript, the scope defines how and in which part of our code we can access the variables and functions. In simple terms, the scope helps us improve our code's security and readability. So, we can access the variables and functions only inside its scope but not outside. We will discuss multiple types of scopes in this tutorial. Global Scope in JavaScript The variables and functions defined globally mean outside all blocks and functions with global scope. We can access all variables and functions with the global scope anywhere inside our code. Syntax Users can ...
Read MoreExplain the benefits of spread syntax & how it is different from rest syntax in ES6?
In the ES6 version of JavaScript, spread syntax is introduced as a very powerful feature. We can use the spread syntax to expand the array or objects into the variable of the same data type. For example, before the spread syntax was introduced in the ES6, developers were using the for loop to copy all elements of one array to another array. Can you copy all elements of one array to another by writing one linear code using the spread syntax rather than writing the 5 to 7 lines of code using the for loop? Yes, you heard right! ...
Read MoreExplain the working of timers in JavaScript
In JavaScript, timers are a very noteworthy feature. As like the normal watch timer, we can start the timer at a time and execute the function or code in JavaScript after a particular time. In simple terms, we can use the timer to execute the code after some delay. For example, when you visit some website, it shows the signup box after 3 to 4 minutes of your visit, and that we can achieve using JavaScript. We can set the delay timer to show the signup popup box. Another good example of the timer in real life is ...
Read MoreExplain the purpose of the 'in' operator in JavaScript
This tutorial will teach about the 'in' operator in JavaScript. There are many operators available in JavaScript, such as arithmetic operators to perform mathematical operations, assignment operators, equality operators, etc. The 'in' operator is also one of them, which we can use to find properties from the object. Before we start, let me ask you a question. Have you ever needed to check for the existence of the object's properties while coding with JavaScript? If yes, how did you deal with it? The answer is simple you can use the 'in' operator, which returns the Boolean value based on ...
Read MoreExplore the concept of JavaScript Function Scope and different types of JavaScript Functions
In JavaScript, various scopes allow us to access the functions and variables from different places in our code. We will learn about the function scope in this tutorial. Also, we will explore the different types of function expressions in JavaScript. Function Scope When we create a new function in JavaScript, it also creates the scope for that particular function. It means that whatever variables we declare inside the function or define the nested function inside it, we can only access it inside the function block. If we try to access the variables defined inside the function block ...
Read MoreExtract unique objects by attribute from an array of objects in JavaScript
We will learn to extract unique objects by attribute from an array of objects in this tutorial. Sometimes, we need to filter objects from the array of objects based on a particular attribute. For example, we have an id as a key to identify the object. So, we need to ensure that the array contains only a single object with a single id. If two or more objects contain the same primary key value, it can cause the problem of uniquely identifying objects. Here, we will learn different approaches to filter all unique objects from the array based ...
Read MoreHow to find the binomial coefficient of two integers using JavaScript?
In this tutorial, we are going to learn how to find the binomial coefficient of two integers using JavaScript. Before learning it we should know what binomial coefficient is and what it refers to. What are Binomial Coefficients? Binomial coefficients refer to the positive integers that occur as coefficients in the binomial theorem. A binomial coefficient C(n, k) can be defined as the coefficient of x^k in the expansion of (1 + x)^n. A binomial coefficient of two numbers n and k signifies the number of combinations of k items that can be selected from a ...
Read MoreHow to find every element that exists in any of two given arrays once using JavaScript?
In this tutorial, we will learn how to find every element that exists in any of two given arrays once. This means creating a new array containing all unique elements from both arrays, with no duplicates. For example, given two arrays: Input const arr1 = [1, 2, 3, 4, 5] const arr2 = [1, 4, 9, 16, 25] Output result = [1, 2, 3, 4, 5, 9, 16, 25] Input const arr1 = ['Deepansh', 'Aditya', 'Rishabh', 'Rishit'] const arr2 = ['Vikrant', 'Rishabh', 'Mohit', 'Rishit'] Output result = ['Deepansh', ...
Read MoreHow to combine multiple elements and append the result into a div using JavaScript?
Sometimes, we require to manipulate the HTML elements using JavaScript. So, we can use JavaScript to add or remove HTML elements. This tutorial will teach us to combine multiple HTML elements in a single shot using JavaScript. Sometimes we need to show some HTML elements to users when they click the button or particular event triggers. So, we can use the approaches below to combine multiple elements and append the result into a div element using JavaScript. Use the innerHTML Property The innerHTML, as the name suggests, allows us to set the HTML for any particular element ...
Read MoreHow to find all elements in a given array except for the first one using JavaScript?
In this tutorial, we will learn how to get all elements from an array except the first one using JavaScript. This is a common operation when you need to remove or skip the first element while processing array data. There are two main approaches to accomplish this task: Using the slice() Method (Recommended) The slice() method creates a shallow copy of a portion of an array. When called with index 1, it returns all elements starting from the second element. Syntax array.slice(startIndex) Example ...
Read More