Javascript Articles

Page 447 of 534

Is it possible to de-structure to already-declared variables? In JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 180 Views

Yes, it is possible to destructure to already-declared variables in JavaScript. However, you must wrap the destructuring assignment in parentheses to avoid syntax errors. The Problem When variables are already declared, JavaScript cannot distinguish between a block statement and destructuring assignment: Destructuring Problem let name, age; ...

Read More

How to transform JavaScript arrays using maps?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 153 Views

JavaScript's map() method creates a new array by transforming each element of the original array using a callback function. It's essential for functional programming and data transformation. Syntax array.map(callback(element, index, array)) Parameters callback - Function that transforms each element element - Current array element being processed index - Index of the current element (optional) array - The original array (optional) Basic Example: Squaring Numbers Transform Arrays with Map ...

Read More

Function borrowing in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 433 Views

Function borrowing in JavaScript allows objects to use methods from other objects without inheriting from them. This is achieved using call(), apply(), and bind() methods. Understanding Function Borrowing When an object doesn't have a particular method but needs to use it, it can "borrow" that method from another object. The borrowed method executes in the context of the borrowing object using the this keyword. Using call() Method The call() method invokes a function with a specific this context and individual arguments. Function Borrowing with call() ...

Read More

Nesting template strings in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 644 Views

Nesting template strings in JavaScript allows you to embed one template literal inside another. This is useful when building complex strings with dynamic content or when passing template literals as function arguments. What are Nested Template Strings? Nested template strings occur when you place one template literal (using backticks) inside another. The inner template string is evaluated first, then the outer one. Basic Syntax `Outer template ${`Inner template ${variable}`} continues here` Simple Example Nested ...

Read More

Awaiting on dynamic imports in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 235 Views

Dynamic imports in JavaScript allow you to load modules asynchronously at runtime using the import() function. This is particularly useful for code splitting and loading modules only when needed. Syntax const module = await import('./modulePath.js'); // or import('./modulePath.js').then(module => { // use module }); How Dynamic Imports Work The import() function returns a Promise that resolves to the module object. You can use await to handle it asynchronously: Dynamic Imports Example ...

Read More

ES6 Property Shorthands in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 226 Views

ES6 introduced property shorthand syntax that simplifies object creation when the property name matches the variable name. Instead of writing name: name, you can simply write name. Syntax // ES5 way let obj = { property: property, anotherProperty: anotherProperty }; // ES6 shorthand let obj = { property, anotherProperty }; Basic Example ES6 Property Shorthands ...

Read More

First class function in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 742 Views

JavaScript treats functions as first-class citizens, meaning they can be stored in variables, passed as arguments, and returned from other functions. This powerful feature enables functional programming patterns and higher-order functions. What are First-Class Functions? In JavaScript, functions are first-class objects, which means they have all the capabilities of other objects. They can be: Stored in variables and data structures Passed as arguments to other functions Returned as values from functions Assigned properties and methods Storing Functions in Variables First-Class Functions // Store function ...

Read More

Asynchronous Functions and the Node Event Loop in Javascript

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 208 Views

Asynchronous functions allow programs to continue executing without waiting for time-consuming operations to complete. This non-blocking behavior is fundamental to JavaScript and Node.js, enabling better user experience and efficient resource utilization. When executing expensive operations like network requests or file I/O, asynchronous functions prevent the entire program from freezing. Instead of blocking execution, these operations run in the background while other code continues to execute. Understanding Asynchronous Execution In synchronous programming, each operation must complete before the next one begins. Asynchronous programming allows multiple operations to run concurrently, with callbacks or promises handling completion. console.log('One'); ...

Read More

Is it possible to have JavaScript split() start at index 1?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 395 Views

The built-in String.prototype.split() method doesn't have a parameter to start splitting from a specific index. However, we can combine split() with array methods like slice() to achieve this functionality. Problem with Standard split() The standard split() method always starts from index 0 and splits the entire string: const text = "The quick brown fox jumped over the wall"; console.log(text.split(" ")); [ 'The', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'wall' ] Method 1: Using split() with slice() The simplest ...

Read More

Sorting arrays by two criteria in JavaScript

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

When sorting arrays by multiple criteria in JavaScript, you need to create a custom comparator function that handles each condition sequentially. This article demonstrates sorting objects by priority (isImportant) first, then by date within each priority group. The Array Structure Consider an array of objects with id, date, and isImportant properties. We want important items first, then sort by date within each group: const array = [{ id: 545, date: 591020824000, isImportant: false, }, { id: 322, ...

Read More
Showing 4461–4470 of 5,340 articles
« Prev 1 445 446 447 448 449 534 Next »
Advertisements