Programming Scripts Articles

Page 9 of 33

How -Infinity is converted to Boolean in JavaScript?

Jai Janardhan
Jai Janardhan
Updated on 15-Mar-2026 251 Views

In JavaScript, -Infinity is considered a truthy value and converts to true when converted to Boolean. This might be surprising since negative infinity seems conceptually "negative, " but JavaScript treats all non-zero numbers (including infinities) as truthy. Using Boolean() Constructor The Boolean() constructor explicitly converts values to their boolean equivalent: Convert -Infinity to Boolean var myVal = -Infinity; document.write("Boolean: ...

Read More

How to work with document.embeds in JavaScript?

Jai Janardhan
Jai Janardhan
Updated on 15-Mar-2026 230 Views

The document.embeds property in JavaScript provides access to all elements in an HTML document. It returns an HTMLCollection containing all embed elements, which is useful for managing embedded content like videos, audio files, or plugins. Syntax document.embeds document.embeds.length document.embeds[index] document.embeds.namedItem(name) Basic Example Here's how to count and access embed elements in a document: Document Embeds Example ...

Read More

How to search the alternate text of an image-map area in JavaScript?

Sravani S
Sravani S
Updated on 15-Mar-2026 211 Views

To search the alternate (alt) text of an image-map area in JavaScript, use the alt property. This property allows you to access or modify the alternative text that describes the image map area for accessibility purposes. Syntax // Get alt text let altText = areaElement.alt; // Set alt text areaElement.alt = "new alt text"; Example: Accessing Alt Text of Image Map Area ...

Read More

How to convert Binary to Decimal in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 6K+ Views

In this tutorial, we will learn to convert binary to decimal in JavaScript. A binary number is a string of '0' and '1' digits, representing numbers in base 2 format used in digital electronics. Here are two different methods to convert binary numbers to decimal: Using the parseInt() Method The parseInt() method can extract numbers from strings and accepts a base parameter, making it perfect for binary conversion. Syntax let binary = "0101"; let decimal = parseInt(binary, 2); Parameters binary − The binary number as a string base − The ...

Read More

How to search and display the pathname part of the href attribute of an area with JavaScript?

Vrundesha Joshi
Vrundesha Joshi
Updated on 15-Mar-2026 200 Views

To get the pathname part of the href attribute of an area in JavaScript, use the pathname property. This property extracts just the path portion from a URL, excluding the protocol, domain, and query parameters. Syntax areaElement.pathname Example You can try to run the following code to display the pathname part of an area element's href attribute. ...

Read More

How to work with document.images in JavaScript?

Arushi
Arushi
Updated on 15-Mar-2026 564 Views

The document.images property in JavaScript provides access to all elements in a document. It returns an HTMLCollection containing all image elements, allowing you to count, access, and manipulate images programmatically. Syntax document.images document.images.length document.images[index] document.images.namedItem(name) Properties and Methods The document.images collection provides: length - Returns the number of images in the document [index] - Access image by numeric index (0-based) namedItem() - Access image by name or id attribute Example: Counting Images ...

Read More

What will happen when 0 is converted to Number in JavaScript?

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 160 Views

Use the Number() method in JavaScript to convert values to Number type. When converting 0 to Number, it remains 0 since it's already a valid number. Basic Conversion Converting 0 to Number returns 0, as zero is already a number: Convert 0 to Number var myVal = 0; document.write("Number: " + Number(myVal)); ...

Read More

What is the role of scrollX property in JavaScript?

Srinivas Gorla
Srinivas Gorla
Updated on 15-Mar-2026 656 Views

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 More

What will happen when 1 is converted to Boolean in JavaScript?

Paul Richard
Paul Richard
Updated on 15-Mar-2026 197 Views

In JavaScript, when the number 1 is converted to Boolean, it becomes true. This is because 1 is considered a "truthy" value in JavaScript's type conversion system. Understanding Truthy and Falsy Values JavaScript has specific rules for Boolean conversion. The number 1 (and all non-zero numbers) are truthy values, meaning they convert to true. Example: Converting 1 to Boolean Convert 1 to Boolean var myVal = 1; document.write("Boolean: " ...

Read More

What is the usage of an abort event in JavaScript?

Sai Nath
Sai Nath
Updated on 15-Mar-2026 488 Views

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
Showing 81–90 of 328 articles
« Prev 1 7 8 9 10 11 33 Next »
Advertisements