Front End Technology Articles

Page 364 of 652

Low level difference between Slice and Splice methods in Javascript

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 483 Views

The slice() and splice() methods are often confused due to their similar names, but they behave very differently. Understanding their key differences is crucial for array manipulation in JavaScript. Key Differences splice() modifies the original array by adding, removing, or replacing elements and returns an array of removed items. slice() creates a shallow copy of a portion of the array without modifying the original and returns the extracted elements. Syntax Comparison // splice syntax array.splice(startIndex, deleteCount, item1, item2, ...) // slice syntax array.slice(startIndex, endIndex) Example: Demonstrating the Difference ...

Read More

What is "undefined x 1" in JavaScript?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 236 Views

The "undefined x 1" notation is not a JavaScript feature but Chrome's way of displaying sparse arrays with uninitialized elements. Instead of showing every undefined value, Chrome uses compact notation for better readability. What Creates "undefined x n" When you create an array with the Array() constructor or have gaps in array indexes, Chrome displays uninitialized slots as "undefined x count": console.log(Array(5)); [undefined × 5] Sparse Arrays Example Arrays with missing indexes also show this notation: let arr = [1, , , 4]; // Missing elements at ...

Read More

Convert the string of any base to integer in JavaScript

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 219 Views

The parseInt() function in JavaScript converts strings representing numbers in any base (2-36) to decimal integers. This is useful when working with binary, octal, hexadecimal, or other numeral systems. Syntax parseInt(string, radix); Parameters string − The value to parse. If not a string, it's converted using the ToString method. Leading whitespace is ignored. radix − An integer between 2 and 36 representing the base of the numeral system. If omitted, defaults to 10 (except for strings starting with "0x" which default to 16). Examples Converting Different Bases to Decimal ...

Read More

What is the difference between `new Object()` and object literal notation in JavaScript?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 706 Views

JavaScript provides two main ways to create objects: new Object() constructor and object literal notation {}. While both create objects, they have important differences in syntax, performance, and flexibility. Object Literal Notation Object literal notation uses curly braces {} to create objects directly with properties: let person = { name: 'Ayush', age: 25, city: 'Delhi' }; console.log(person.name); console.log(person); Ayush { name: 'Ayush', age: 25, city: 'Delhi' } Using new Object() Constructor The new Object() constructor creates an ...

Read More

What is JSlint error "missing radix parameter" in JavaScript?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 1K+ Views

The parseInt function in JavaScript has the following signature: parseInt(string, radix); Where the parameters are: string − The value to parse. If this argument is not a string, then it is converted to one using the ToString method. Leading whitespace in this argument is ignored. radix − An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the string. The Problem: Omitting the Radix Parameter If the radix parameter is omitted, JavaScript assumes the following: If the string begins ...

Read More

Query-string encoding of a Javascript Object

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 257 Views

The query string is made up of query parameters and used to send data to the server. This part of the URL is optional and needs to be constructed by the developer. This can be done using a native method called encodeURIComponent(). The encodeURIComponent() function encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character. Using Object.keys() and map() Using ES6 features, objects can be query string encoded by combining Object.keys(), map(), and join() methods: let ...

Read More

Increment a date in javascript without using any libraries?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 229 Views

To increment a date in JavaScript without external libraries, use the setDate() method. This approach automatically handles month and year rollovers. Using setDate() Method The setDate() method accepts day values beyond the current month's range. JavaScript automatically adjusts the month and year when necessary. let date = new Date('2024-01-31'); // January 31st date.setDate(date.getDate() + 1); // Add 1 day console.log(date.toDateString()); Thu Feb 01 2024 Creating a Reusable Function You can extend the Date prototype or create a standalone function to add days: Date.prototype.addDays = function(days) { ...

Read More

How to create an object property from a variable value in JavaScript?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 9K+ Views

JavaScript has two notations for creating object properties: dot notation and bracket notation. To create an object property from a variable value, you need to use bracket notation or ES6 computed property names. Method 1: Using Bracket Notation (Dynamic Assignment) You can assign properties to existing objects using bracket notation with variable names: const obj = {a: 'foo'}; const prop = 'bar'; // Set the property using the variable name prop obj[prop] = 'baz'; console.log(obj); { a: 'foo', bar: 'baz' } Method 2: Using ES6 Computed Property Names ES6 ...

Read More

Jasmine JavaScript Testing - toBe vs toEqual

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 910 Views

In Jasmine JavaScript testing, toBe and toEqual are two different matchers for comparing values. Understanding their difference is crucial for writing effective tests. toBe vs toEqual Overview Arrays and objects can be compared in two ways: Reference equality: They refer to the same object in memory Value equality: They may refer to different objects but their contents are identical Using toBe (Reference Equality) The toBe matcher checks if two variables reference the exact same object in memory. It uses JavaScript's === operator internally. ...

Read More

What blocks Ruby, Python to get Javascript V8 speed?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 164 Views

Nothing technically prevents Ruby and Python from achieving JavaScript V8 speeds. The performance gap exists primarily due to differences in optimization investments and language design choices rather than fundamental limitations. The V8 Advantage Google's V8 engine benefits from massive engineering resources and specific optimizations: Just-In-Time (JIT) compilation: Converts JavaScript to optimized machine code at runtime Hidden class optimization: Optimizes object property access patterns Inline caching: Speeds up method calls and property lookups Garbage collection tuning: Minimizes pause times during memory cleanup Ruby and Python Constraints Several factors limit Ruby and Python performance compared ...

Read More
Showing 3631–3640 of 6,519 articles
« Prev 1 362 363 364 365 366 652 Next »
Advertisements