Articles on Trending Technologies

Technical articles with clear explanations and examples

Usage of rest parameter and spread operator in JavaScript?

Anjana
Anjana
Updated on 15-Mar-2026 407 Views

Rest parameters and spread operators use the same three-dot syntax (...) but serve different purposes. Rest parameters collect multiple arguments into an array, while spread operators expand arrays or objects into individual elements. Rest Parameters Rest parameters allow functions to accept an indefinite number of arguments as an array. They must be the last parameter in a function's parameter list. Syntax function functionName(...parameterName) { // parameterName is an array containing all arguments } Example ...

Read More

How to use Spread Syntax with arguments in JavaScript functions?

Abhishek Kumar
Abhishek Kumar
Updated on 15-Mar-2026 2K+ Views

We use the Spread Syntax of JavaScript to expand an array, string, or object in place. Such types of values are called iterable. This is similar to destructuring the iterable in place. Its utility in a function call allows us to extract function parameters from an iterable. In this tutorial, we learn how to use Spread Syntax with arguments in JavaScript functions. Spread operator in JavaScript A Spread operator, denoted with (...) followed by the name of the iterable expands the iterable into its constituent elements. Example of spread in destructuring: const [x, y, ...z] ...

Read More

What are generator functions in JavaScript?

Prabhas
Prabhas
Updated on 15-Mar-2026 359 Views

Generator functions in JavaScript allow you to pause and resume function execution, providing powerful control over program flow. Unlike regular functions that run to completion, generators can yield values multiple times and maintain their internal state between calls. Syntax Generator functions are defined using the function* syntax with an asterisk. The asterisk can be placed in different positions: function* myGenerator() {} // or function *myGenerator() {} // or function*myGenerator() {} How Generator Functions Work Generator functions use the yield keyword to pause execution and return a value. When called, they return a generator ...

Read More

How to define functions inside a function body in JavaScript?

mkotla
mkotla
Updated on 15-Mar-2026 263 Views

To define functions inside a function body in JavaScript, you can use nested function declarations or function expressions. This creates closures that have access to the outer function's scope. Basic Nested Function Functions declared inside another function are only accessible within that parent function: function outerFunction() { function innerFunction() { console.log("Hello from inner function!"); } innerFunction(); // Call the nested function } outerFunction(); Hello from inner function! ...

Read More

How to pass the value 'undefined' to a function with multiple parameters in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 4K+ Views

In this tutorial, we will learn how to pass the value 'undefined' to a function with multiple parameters in JavaScript. In JavaScript, the data type of 'undefined' is primitive. When a variable is declared, JavaScript automatically assigns the value 'undefined' to it. If a function has multiple parameters and one of the parameters' values is not available at the moment, then we need to omit that parameter's value from the function call. But if we omit the parameter's value with a blank space, the JavaScript will show an error. The Problem function abc(param1, param2, param3) { ...

Read More

How to use a line break in array values in JavaScript?

Abhishek Kumar
Abhishek Kumar
Updated on 15-Mar-2026 15K+ Views

We use the join() method of JavaScript to use a line break in array values. It allows us to concatenate all the constituent elements of an array into a single string using a common separator. The join() method in JavaScript The join() method takes as input a single separator string and returns a string with all the elements of the array separated by the specified separator string. The separator string by default is the comma(, ). The join method uses the toString() method to convert the elements of the array into corresponding strings. A null or undefined ...

Read More

What is lexical this in JavaScript?

Sreemaha
Sreemaha
Updated on 15-Mar-2026 2K+ Views

In JavaScript, "lexical this" refers to how arrow functions inherit the this context from their enclosing scope, unlike regular functions that define their own this. This solves common issues with this binding in callbacks and nested functions. The Problem with Regular Functions Regular functions create their own this context, which can lead to unexpected behavior in callbacks: Click Me document.getElementById('myButton').addEventListener('click', function() { console.log('Outer this:', this); // Points to the button setTimeout(function() { console.log('Inner ...

Read More

What is a fat arrow function in JavaScript?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 723 Views

Fat arrow functions (also called arrow functions) were introduced in ES6 to provide a shorter syntax for writing functions. They use the => syntax, which resembles a "fat arrow", eliminating the need to write the function keyword repeatedly. Syntax For a single argument: argument => expression For multiple arguments or no arguments: (argument1, argument2) => expression // or () => expression Example: Traditional vs Arrow Function Traditional Function: var rank = [7, 8, 9]; var display = rank.map(function(num) { return num * num; ...

Read More

Why avoid increment ("++") and decrement ("--") operators in JavaScript?

Rahul Sharma
Rahul Sharma
Updated on 15-Mar-2026 545 Views

The increment (++) and decrement (--) operators in JavaScript can lead to confusing code and unexpected results due to their pre-increment and post-increment behavior. Understanding why they should be avoided helps write clearer, more maintainable code. Pre-increment vs Post-increment Confusion The main issue with increment operators is the difference between pre-increment (++a) and post-increment (a++), which can produce unexpected values in assignments: var a = 5; var b = ++a; // Pre-increment: a becomes ...

Read More

What is decrement (--) operator in JavaScript?

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 757 Views

The decrement operator in JavaScript decreases an integer value by one. This operator is often utilized in loops, counters, and mathematical computations where a value has to be decreased sequentially. Types of Decrement Operators The decrement operator (--) can be used in two ways: Post-decrement (x--): Returns the current value of the variable first, then decrements it. Pre-decrement (--x): Decrements the value first, then returns the new value. Syntax x--; // Post-decrement --x; // Pre-decrement Pre-decrement Example Pre-decrement decreases the value ...

Read More
Showing 19121–19130 of 61,297 articles
Advertisements