Object Oriented Programming Articles

Page 87 of 589

Regular functions vs Arrow functions in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 655 Views

Arrow functions and regular functions are both ways to define functions in JavaScript, but they have important differences in behavior. Understanding these differences helps you choose the right function type for your needs. Syntax The syntax differs between regular and arrow functions: Arrow Function Syntax let x = (params) => { // code }; Regular Function Syntax let x = function functionName(params) { // code }; Usage of "this" Keyword The most significant difference is how they handle the this ...

Read More

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

Is JavaScript a pass-by-reference or pass-by-value language?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 601 Views

JavaScript provides functions that contain a collection of instructions executed when called. These functions can accept arguments as input, and understanding how JavaScript passes these arguments is crucial for effective programming. JavaScript uses pass by value for all function parameters. This means JavaScript creates copies of variable values when passing them to functions. However, the behavior differs between primitive types and objects due to how JavaScript handles references. Pass By Value (Primitives) For primitive data types (numbers, strings, booleans), JavaScript creates a complete copy of the value. Changes inside the function don't affect the original variable. ...

Read More

Difference between shift() and pop() methods in Javascript

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

The shift() method removes the element at the first index (index 0) and shifts all remaining elements down by one position, then returns the removed value. If the array is empty, it returns undefined. The pop() method removes the last element from an array and returns that element. This method changes the length of the array. Syntax array.shift() // Removes first element array.pop() // Removes last element Example: Comparing shift() and pop() let fruits = ['apple', 'mango', 'orange', 'kiwi']; let fruits2 = ['apple', 'mango', 'orange', 'kiwi']; ...

Read More

Difference between push() and unshift() methods in javascript

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

JavaScript arrays provide two methods for adding elements: push() adds elements at the end, while unshift() adds elements at the beginning. Both methods modify the original array and return the new array length. push() Method The push() method adds one or more elements to the end of an array and returns the new length of the array. let fruits = ['apple', 'mango', 'orange']; console.log("Original array:", fruits); let newLength = fruits.push('kiwi'); console.log("After push():", fruits); console.log("New length:", newLength); Original array: [ 'apple', 'mango', 'orange' ] After push(): [ 'apple', 'mango', 'orange', 'kiwi' ] New ...

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

Passing unknown number of arguments to a function in Javascript

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 3K+ Views

JavaScript allows functions to accept any number of arguments, even if the function definition specifies a different number of parameters. This flexibility is useful when creating functions that need to handle variable amounts of data. When defining a function, the variables listed in parentheses are called parameters. When calling the function, the actual values passed are called arguments. JavaScript provides two main approaches to handle unknown numbers of arguments. Basic Example: Fixed Parameters Functions with fixed parameters will only use the specified number of arguments, ignoring any extras: Passing ...

Read More

Which algorithm does the JavaScript Array#sort() function use?

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

JavaScript's Array.sort() method doesn't mandate a specific sorting algorithm in the ECMAScript specification. This gives JavaScript engines freedom to choose the most efficient implementation for their environment. Engine-Specific Implementations Different JavaScript engines use different sorting strategies based on performance optimizations and array characteristics. Mozilla Firefox (SpiderMonkey) SpiderMonkey primarily uses merge sort, which provides stable O(n log n) performance. The implementation can be found in Mozilla's C codebase. Chromium/WebKit (V8 Engine) V8 uses a hybrid approach called Timsort (based on merge sort and insertion sort) for optimal performance across different data patterns. The algorithm selection depends on: ...

Read More

Convert the string of any base to integer in JavaScript

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 218 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

Difference between regular functions and arrow functions in JavaScript

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

According to MDN, an arrow function expression is a syntactically compact alternative to a regular function expression, although without its own bindings to the this, arguments, super, or new.target keywords. Arrow function expressions are ill suited as methods, and they cannot be used as constructors. There are three key differences between regular functions and arrow functions in JavaScript that affect how they behave in your code. No Own this Bindings Arrow functions do not have their own this value. The value of this inside an arrow function is always inherited from the enclosing scope, while regular functions ...

Read More
Showing 861–870 of 5,881 articles
« Prev 1 85 86 87 88 89 589 Next »
Advertisements