Object Oriented Programming Articles

Page 80 of 589

How to find the minimum value of an array in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 3K+ Views

JavaScript provides several methods to find the minimum value in an array. The most efficient approach is using Math.min() with the spread operator, though other methods like sorting are also available. Using Math.min() with Spread Operator (Recommended) The Math.min() function finds the smallest number among its arguments. Combined with the spread operator (...), it can easily find the minimum value in an array. Find Minimum function findMinimum() { var numbers = [6, 39, 55, 1, 44]; var minimum = Math.min(...numbers); ...

Read More

What is the difference between Math.ceil() and Math.round() methods in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 6K+ Views

Math.ceil() and Math.round() are JavaScript methods that round numbers to integers, but they work differently. Math.ceil() always rounds up to the nearest integer, while Math.round() rounds to the nearest integer using standard rounding rules (0.5 and above rounds up, below 0.5 rounds down). Math.ceil() - Always Rounds Up The Math.ceil() method rounds a number up to the nearest integer, regardless of the decimal value. It always moves toward the greater value. Syntax Math.ceil(x) Example ...

Read More

Explain in detail about the memory life cycle of JavaScript?

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

JavaScript's memory management is crucial for application performance. Understanding the memory lifecycle helps developers write more efficient code and avoid memory leaks. The Three Stages of Memory Lifecycle Every programming language follows a similar memory lifecycle with three fundamental stages: Allocation of memory - Reserve memory space for variables and objects Use the allocated memory - Read from and write to the allocated memory Release the allocated memory - Free up memory when it's no longer needed In low-level languages, developers manually handle allocation and deallocation. However, high-level languages like JavaScript manage this process ...

Read More

Explain in detail about Reference-counting garbage collection in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 3K+ Views

Reference-counting garbage collection is the simplest garbage collection algorithm used in JavaScript. This algorithm monitors objects and removes those that have no references pointing to them. An object becomes eligible for garbage collection when its reference count drops to zero. How Reference-Counting Works The algorithm maintains a count of how many references point to each object. When a reference is created, the count increases. When a reference is removed, the count decreases. Objects with zero references are immediately marked for garbage collection. Example: Basic Reference Counting var obj = { x: ...

Read More

Explain in detail about Mark and Sweep algorithm in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 1K+ Views

Mark and Sweep Algorithm The Mark and Sweep algorithm is JavaScript's primary garbage collection method that identifies objects "which are unreachable" rather than objects "which are no longer needed". This algorithm is an improvement over the Reference-counting algorithm and solves the circular reference problem. How Mark and Sweep Works The algorithm operates in three important steps: Root Identification: The algorithm starts from "roots" - global variables accessible in the code. In browsers, the window object acts as the primary root. Marking Phase: The algorithm traverses from roots to find ...

Read More

How can Detached DOM elements cause memory leak in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 2K+ Views

Detached DOM elements are nodes that have been removed from the DOM tree but still exist in memory because JavaScript variables maintain references to them. This prevents the garbage collector from freeing the memory, leading to memory leaks. Understanding DOM Tree Structure The DOM is a double-linked tree structure where each node holds references to its parent and children. When you maintain a JavaScript reference to any node, the entire subtree remains in memory even after removal from the visible DOM. DOM Tree ...

Read More

How can Forgotten timers or callbacks cause memory leaks in JavaScript?

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

JavaScript memory leaks commonly occur when timers and callbacks maintain references to objects that should be garbage collected. Understanding these patterns helps prevent memory issues in web applications. How Timers Create Memory Leaks When objects are referenced inside timer callbacks, the garbage collector cannot release them until the timer completes. If timers run indefinitely or reset themselves, the referenced objects remain in memory permanently. Timer Functions Overview JavaScript provides two main timing functions: setTimeout() - Executes a function once after a specified delay setInterval() - Executes a function repeatedly at specified intervals ...

Read More

How to implement quick sort in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 3K+ Views

In this article, we are going to discuss how to implement quick sort in JavaScript with suitable examples. Quick Sort The Quick sort is a divide and conquer algorithm similar to the merge sort. In this, we pick a pivot element and divide the array around the pivot element. There are many ways to pick the pivot element. Always pick the first element as a pivot element. Always pick the last element as a pivot element. (Implemented in the below program) Pick a random element as pivot ...

Read More

How can closures cause memory leak and how to prevent it?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 2K+ Views

Closures are one of JavaScript's powerful features, allowing inner functions to access variables from their outer (parent) functions. However, this can sometimes lead to memory leaks when variables remain in memory longer than necessary. Understanding Closure Memory Leaks A memory leak occurs when variables from outer functions remain accessible to inner functions, preventing garbage collection even when those variables aren't actively used. The JavaScript engine keeps these variables in memory because the inner function might reference them. Example of Potential Memory Leak function parentFunction(arg1) { ...

Read More

How to freeze an Object in JavaScript?

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

In JavaScript, Object.freeze() makes an object immutable by preventing modifications to its properties. Once frozen, you cannot add, delete, or modify properties of the object. Syntax Object.freeze(obj) Parameters obj: The object to freeze. Returns the same object that was passed to the function. How Object.freeze() Works When an object is frozen: New properties cannot be added Existing properties cannot be removed Existing property values cannot be changed The object's prototype cannot be changed Example: Basic Object Freezing // Create an object with properties ...

Read More
Showing 791–800 of 5,881 articles
« Prev 1 78 79 80 81 82 589 Next »
Advertisements