Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
How can I get a JavaScript stack trace when I throw an exception?
This tutorial teaches us to get a JavaScript stack trace when we throw an exception. Usually, the developer uses the stack trace to identify the errors while executing the program's code. However, we use the stack trace to debug the program. Using the stack trace, we can get knowledge of any kind of exceptions, such as constructor error, naming error, etc., in our program, and we can correct them. Before we approach analyzing the error using the stack trace, we should know how to stack trace works. How does the call stack trace work? The stack ...
Read MoreHow to stop the execution of a function with JavaScript?
To stop the execution of a function in JavaScript, you have several methods depending on the type of execution. The most common approaches involve clearing timers or using control flow statements. Using clearTimeout() for setTimeout() The clearTimeout() method stops functions scheduled with setTimeout(): Stop Function Execution Click the buttons below to handle animation Start Stop var ...
Read MoreDoes use of anonymous functions affect performance?
Anonymous functions in JavaScript have minimal performance impact in modern engines. While they create new function objects each time, the difference is negligible unless used in tight loops or performance-critical code. What are Anonymous Functions? Anonymous functions are functions without a name identifier. They are typically assigned to variables or passed as arguments to other functions. var func = function() { console.log('This is anonymous'); } func(); This is anonymous Performance Comparison Here's a comparison between named and anonymous functions: // Named function ...
Read MorePerform basic HTML5 Canvas animation
HTML5 canvas provides the necessary methods to draw and manipulate graphics dynamically. Combined with JavaScript, we can create smooth animations by continuously redrawing the canvas content at regular intervals. How Canvas Animation Works Canvas animation involves three key steps: Clear the canvas - Remove previous frame content Draw new content - Render the updated animation frame Repeat - Use timers to create continuous motion Basic Rotating Image Animation Here's a complete example that rotates an image around the canvas center: ...
Read MoreHow to use spread operator to join two or more arrays in JavaScript?
The spread operator (...) provides a clean, modern way to join multiple arrays in JavaScript. It can be used for both immutable merging (creating new arrays) and mutable merging (modifying existing arrays). What is the Spread Operator? The spread operator (...) expands array elements, allowing you to copy values from one array to another. It performs a shallow copy of the original array. const mergedArray = [...array1, ...array2]; Method 1: Immutable Array Joining This approach creates a new array containing elements from all source arrays, leaving the original arrays unchanged. Joining Two ...
Read MoreStrict equality vs Loose equality in JavaScript.
In JavaScript, there are two ways to compare values for equality: loose equality (==) and strict equality (===). Understanding the difference is crucial for writing reliable code. Loose Equality (==) The loose equality operator == compares values after converting them to a common type (type coercion). This can lead to unexpected results. Loose Equality Examples Loose Equality Results ...
Read MoreFilter away object in array with null values JavaScript
When working with arrays of objects, you often need to filter out objects with invalid or empty values. This is common when processing API responses or user data that may contain incomplete records. Let's say we have an array of employee objects, but some have empty strings, null, or undefined values for the name field. We need to filter out these invalid entries. Sample Data Here's our employee data with some invalid entries: let data = [{ "name": "Ramesh Dhiman", "age": 67, "experience": ...
Read MoreChecking the intensity of shuffle of an array - JavaScript
An array of numbers is 100% shuffled if no two consecutive numbers appear together in ascending order. It is 0% shuffled if all adjacent pairs are in ascending order. The shuffle intensity measures how much an array deviates from a perfectly sorted ascending sequence. For an array of length n, there are n-1 adjacent pairs to examine. We calculate the percentage of pairs that are NOT in ascending order. How It Works The algorithm counts pairs where the first element is greater than the second element (descending pairs). The shuffle intensity is calculated as: Shuffle ...
Read MoreWhat is the usage of onhashchange event in JavaScript?
The onhashchange event occurs when the anchor part (hash) of the URL changes. This event is useful for creating single-page applications where different URL fragments represent different views or states. Syntax window.onhashchange = function() { // Code to execute when hash changes }; // Or using addEventListener window.addEventListener('hashchange', function() { // Code to execute when hash changes }); Example: Basic Hash Change Detection Change to #about Change to #contact ...
Read MoreHow do I clear the usage of setInterval()?
The setInterval() method executes a function repeatedly at specified intervals. Unlike setTimeout() which runs once, setInterval() continues indefinitely until cleared. Syntax let intervalId = setInterval(function, delay); Example: Basic setInterval Usage let count = 0; let intervalId = setInterval(function() { count++; console.log("Hello " + count); // Stop after 3 executions if (count === 3) { clearInterval(intervalId); ...
Read More