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 to catch all JavaScript errors?
To catch all JavaScript errors, we can use the window.onerror method which acts like a global try-catch statement. The onerror event handler was the first feature to facilitate error handling in JavaScript. The error event is fired on the window object whenever an exception occurs on the page. The onerror event handler provides three pieces of information to identify the exact nature of the error: Error message − The same message that the browser would display for the given error URL − The file in which the error occurred ...
Read MoreWhat is the role of scrollX property in JavaScript?
The scrollX property in JavaScript returns the number of pixels the document has been scrolled horizontally from the left edge of the viewport. It's equivalent to the older pageXOffset property and is read-only. Syntax let horizontalScroll = window.scrollX; Return Value Returns a number representing the horizontal scroll position in pixels. The value is 0 when the document is not scrolled horizontally. Example: Basic scrollX Usage .content { ...
Read MoreHow to set the order of the flexible item, relative to the rest with JavaScript?
To set the order of flexible items relative to each other in JavaScript, use the order property. This CSS property controls the visual order of flex items without changing the HTML structure. Syntax element.style.order = "value"; The order property accepts integer values (positive, negative, or zero). Items with lower values appear first, and items with the same order value appear in their original HTML order. Example Here's how to reorder flex items dynamically using JavaScript: ...
Read MoreHTML5 Geolocation in Safari 5
HTML5 Geolocation API lets you share your location with your favorite web sites. A JavaScript can capture your latitude and longitude, can be sent to backend web server, and do fancy location-aware things like finding local businesses or showing your location on a map. How Geolocation Works The Geolocation API uses navigator.geolocation to access device location. It requires user permission and works through GPS, WiFi, or IP-based positioning. Basic Syntax navigator.geolocation.getCurrentPosition(successCallback, errorCallback, options); Example: Getting Current Position Here's how to get the user's current location: ...
Read MoreComposition attribute in HTML5 Canvas?
HTML5 Canvas provides the globalCompositeOperation property that controls how new shapes are drawn on top of existing shapes. This property determines the compositing behavior when overlapping occurs. Syntax context.globalCompositeOperation = "composite-operation"; Available Composite Operations The globalCompositeOperation property accepts several values that define different blending modes: source-over (default): New shapes are drawn on top source-in: New shapes are drawn only where they overlap existing content source-out: New shapes are drawn only where they don't overlap destination-over: New shapes are drawn behind existing content lighter: Colors are added together for brighter results copy: Only ...
Read MoreHow to find maximum value in an array using spread operator in JavaScript?
In this article, we will learn how to find the maximum value in an array using the spread operator with Math.max() in JavaScript. This approach is much cleaner and more efficient than passing array elements individually. What is the Spread Operator? The spread operator (...) expands an array or object into individual elements. It's perfect for passing array elements as separate arguments to functions like Math.max(). // Syntax Math.max(...arrayName) The Problem with Manual Approach Without the spread operator, you'd need to pass each array element individually to Math.max(), which becomes tedious for large ...
Read MoreJavaScript Count characters case insensitive
Counting characters in a string is a common task in programming, especially when analyzing text or creating applications that handle user input. Counting characters in a string without worrying about uppercase or lowercase letters is a common task in text processing and data analysis. JavaScript offers different methods to easily count how many times each character appears, regardless of case. Understanding Case Insensitive Case insensitivity in programming means that a system treats uppercase and lowercase letters as the same. For example, "Hello" and "hello" would be treated as ...
Read MoreFinding the nth day from today - JavaScript (JS Date)
We are required to write a JavaScript function that takes in a number n as the only input. The function should first find the current day (using Date Object in JavaScript) and then the function should return the day n days from today. For example − If today is Monday and n = 2, Then the output should be − Wednesday Understanding the Problem JavaScript's Date.getDay() returns 0 for Sunday, 1 for Monday, and so on. We need to handle the modulo operation correctly to cycle through weekdays. Method 1: ...
Read MoreHow to catch syntax errors in JavaScript?
In this tutorial, we will learn how to catch syntax errors in JavaScript and handle them effectively. JavaScript throws various types of errors when we write incorrect code: ReferenceError when calling undefined variables, TypeError when trying to modify immutable values inappropriately, and SyntaxError when the code structure is invalid. What is Syntax Error? A SyntaxError occurs when JavaScript encounters code that violates the language's syntax rules. Unlike runtime errors, syntax errors are detected during the parsing phase, before the code executes. Common Causes of Syntax Errors Missing brackets: Unclosed parentheses (), braces ...
Read MoreWhat is the usage of an abort event in JavaScript?
The abort event fires when the loading of a media resource is aborted, typically for images, videos, or audio elements. This event occurs when the user navigates away from the page or explicitly stops the loading process before it completes. When the abort Event Occurs The abort event is triggered in several scenarios: User navigates away from the page while an image is loading Loading is interrupted by clicking a link or refreshing the page Network connection is lost during resource loading The loading process is programmatically canceled Example: Basic abort Event Handler ...
Read More