Web Development Articles

Page 434 of 801

How to declare Block-Scoped Variables in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 279 Views

Block-scoped variables are declared using let and const keywords introduced in ES2015. Unlike var, these variables are only accessible within their containing block. Block scope means the variable exists only within the nearest enclosing curly braces {}. Syntax let variableName = value; const constantName = value; Example: Basic Block Scope Block Scoped Variables Block Scoped Variables Demo Test Block Scope ...

Read More

Object.fromEntries() method in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 210 Views

The Object.fromEntries() method in JavaScript converts an iterable of key-value pairs (like arrays or Maps) into an object. It's the reverse operation of Object.entries(). Syntax Object.fromEntries(iterable) Parameters iterable: An iterable containing key-value pairs, such as an array of arrays or a Map. Return Value Returns a new object with properties derived from the key-value pairs in the iterable. Example: Converting Array of Arrays Object.fromEntries() Example Object.fromEntries() ...

Read More

Explain Optional Catch Binding in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 517 Views

The optional catch binding introduced in ES2019 allows us to omit the error parameter in catch blocks. Instead of catch(error), we can simply write catch when we don't need to access the error object. This feature is useful when we know the type of error in advance or want to handle errors without examining their details. Syntax Comparison Traditional catch binding requires parentheses and a parameter: try { // code that might throw } catch (error) { // handle error using 'error' parameter } Optional ...

Read More

Separate a string with a special character sequence into a pair of substrings in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 756 Views

When you have a string containing a special character sequence that acts as a delimiter, you can separate it into substrings using JavaScript's split() method with regular expressions. Problem Statement Consider this string with a special character sequence: " John Smith " We need to split this string at the delimiter and get clean substrings without extra whitespace. Syntax var regex = /\s*\s*/g; var result = string.trim().split(regex); Example var fullName = " John Smith "; console.log("Original string: " + fullName); var regularExpression = ...

Read More

Object de-structuring in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 168 Views

Object destructuring is a JavaScript feature that allows you to extract multiple properties from an object and assign them to variables in a single statement. It provides a clean and concise way to work with object properties. Syntax const { property1, property2, property3 } = object; Basic Example Object Destructuring Object Destructuring Example ...

Read More

Get global variable dynamically by name string in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 539 Views

In JavaScript, you can access global variables dynamically using their name as a string through the window object (in browsers) or global object (in Node.js). Syntax // Browser environment window[variableName] // Node.js environment global[variableName] // Using globalThis (works in both) globalThis[variableName] Basic Example Dynamic Global Variables // Define global variables ...

Read More

Is it possible to display substring from object entries in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 336 Views

Yes, you can display substrings from object entries in JavaScript using Object.fromEntries() combined with string methods like substr() or substring(). This technique allows you to transform object keys while preserving their associated values. Syntax Object.fromEntries( Object.entries(object).map(([key, value]) => [key.substr(startIndex, length), value] ) ) Example: Extracting Substring from Object Keys const originalString = { "John 21 2010": 1010, "John 24 2012": 1011, "John 22 2014": ...

Read More

How to make Format ABC-1234 in JavaScript regular Expressions?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 358 Views

In JavaScript, you can format strings to match the pattern ABC-1234 using regular expressions. This pattern consists of three uppercase letters followed by a dash and four digits. Understanding the Pattern The ABC-1234 format requires: Three uppercase letters (A-Z) A dash (-) Four digits (0-9) Regular Expression Pattern The regex pattern for ABC-1234 format is: /^[A-Z]{3}-\d{4}$/ Breaking down this pattern: ^ - Start of string [A-Z]{3} - Exactly 3 uppercase letters - - Literal dash character \d{4} - Exactly 4 digits $ - End of string Method ...

Read More

Remove same values from array containing multiple values JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 245 Views

In JavaScript, arrays often contain duplicate values that need to be removed. The most efficient modern approach is using Set with the spread operator to create a new array with unique values only. Example Array with Duplicates Let's start with an array containing duplicate student names: const listOfStudentName = ['John', 'Mike', 'John', 'Bob', 'Mike', 'Sam', 'Bob', 'John']; console.log("Original array:", listOfStudentName); Original array: [ 'John', 'Mike', 'John', 'Bob', 'Mike', 'Sam', 'Bob', 'John' ] Using Set with Spread Operator (Recommended) The Set object automatically removes duplicates, and the spread operator converts it ...

Read More

The onchange event is not working in color type input with JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

The onchange event works perfectly with color input elements in JavaScript. When a user selects a different color, the event triggers automatically, allowing you to capture and process the new color value. Syntax Basic Example Color Input onchange Event Choose Color: ...

Read More
Showing 4331–4340 of 8,010 articles
« Prev 1 432 433 434 435 436 801 Next »
Advertisements