Object Oriented Programming Articles

Page 110 of 589

How to check if a document is ready in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 792 Views

In JavaScript, you can check if the DOM is fully loaded using document.readyState or event listeners. This is crucial for ensuring your scripts run after the HTML structure is ready. Understanding document.readyState The document.readyState property has three possible values: "loading" - The document is still loading "interactive" - The document has loaded but resources like images may still be loading "complete" - The document and all resources have finished loading Method 1: Using document.readyState Document Ready ...

Read More

Can we re-throw errors in JavaScript? Explain.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 266 Views

Yes, JavaScript allows you to re-throw errors after catching them using the throw statement inside a catch block. This technique is useful for conditional error handling, logging, or passing errors up the call stack. What is Re-throwing? Re-throwing means catching an error, performing some operation (like logging or validation), and then throwing the same or a new error to be handled elsewhere. Basic Syntax try { // Code that may throw an error } catch (error) { // Handle or log the error ...

Read More

TextDecoder and TextEncoder in Javascript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 687 Views

TextEncoder and TextDecoder are modern JavaScript APIs that handle text encoding and decoding operations. TextEncoder converts strings to UTF-8 bytes, while TextDecoder converts byte arrays back to strings with support for multiple character encodings. TextEncoder Overview TextEncoder converts JavaScript strings into UTF-8 encoded Uint8Array. It only supports UTF-8 encoding and provides a simple encode() method. TextEncoder Example ...

Read More

Calculating average of an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 615 Views

Calculating the average of an array is a common task in JavaScript. The average is computed by summing all elements and dividing by the array length. Basic Formula Average = (Sum of all elements) / (Number of elements) Method 1: Using forEach Loop Calculate Array Average Calculating Average of an Array Array: Calculate Average ...

Read More

How to convert an Image to blob using JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 16K+ Views

Converting an image to a blob in JavaScript allows you to work with binary image data for file uploads, downloads, or processing. A blob (Binary Large Object) represents immutable binary data that can be read as text or binary data. What is a Blob? A blob is a file-like object that contains raw binary data. When you convert an image to a blob, you get access to properties like size and MIME type, making it useful for file operations. Using fetch() to Convert Image URL to Blob The most common approach is using the fetch API ...

Read More

How to access JavaScript properties?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 335 Views

In JavaScript, there are three main ways to access object properties. Each method has specific use cases and advantages depending on the situation. Three Methods to Access Properties Dot notation: object.property Square bracket notation: object['property'] Object destructuring: let {property} = object Method 1: Using Dot Notation The dot notation is the most common and readable way to access properties when the property name is known at compile time. ...

Read More

File and FileReader in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 413 Views

The File and FileReader APIs in JavaScript allow web applications to read and process files selected by users. The File object represents file information, while FileReader enables reading file contents asynchronously. File Object Properties When a user selects a file through an input element, you get access to a File object with these key properties: name - The file's name size - File size in bytes type - MIME type of the file lastModified - Last modification timestamp FileReader Methods FileReader provides several methods to read file contents: readAsText() - Reads ...

Read More

Flattening multi-dimensional arrays in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 447 Views

JavaScript arrays can be nested to create multi-dimensional structures. Flattening converts these nested arrays into a single-level array. The flat() method provides a clean solution for this operation. Syntax array.flat(depth) Parameters depth (optional): The number of nested levels to flatten. Default is 1. Use Infinity to flatten all levels. Basic Example Array Flattening Demo Flattening Multi-dimensional Arrays ...

Read More

How to create a URL object using JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 560 Views

The URL object in JavaScript provides a convenient way to parse and manipulate URLs. It extracts components like protocol, host, pathname, and search parameters from URL strings. Syntax let url = new URL(urlString); let url = new URL(urlString, baseURL); Parameters urlString - The URL string to parse baseURL - (Optional) Base URL for relative URLs Example URL Object Example body { ...

Read More

Product of all other numbers an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 393 Views

Let's say, we have to write a function that takes an array of numbers as argument. We have to return a new array with the products of each number except the index we are currently calculating product for. For example, if arr had 5 indices and we were creating the value for index 1, the numbers at index 0, 2, 3 and 4 would be multiplied. Similarly, if we were creating the value for index 2, the numbers at index 0, 1, 3 and 4 would be multiplied and so on. Note − It is guaranteed that all ...

Read More
Showing 1091–1100 of 5,881 articles
« Prev 1 108 109 110 111 112 589 Next »
Advertisements