AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 451 of 840

JavaScript: Finding nearest prime number greater or equal to sum of digits - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 229 Views

We are required to write a JavaScript function that takes in a number, finds the sum of its digits and returns a prime number that is just greater than or equal to the sum. Understanding the Problem For a number like 56563, we first calculate the sum of digits: 5 + 6 + 5 + 6 + 3 = 25. Since 25 is not prime (divisible by 5), we find the next prime number, which is 29. Example const num = 56563; const digitSum = (num, sum = 0) => { ...

Read More

Explain touch events in JavaScript

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

Touch events in JavaScript are fired when a user interacts with a touchscreen device. These events provide a way to handle touch-based interactions on mobile devices, tablets, and other touch-enabled screens. Touch Event Types JavaScript provides four main touch events for handling different stages of touch interaction: Event Description ...

Read More

The image() object in JavaScript.

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

The Image object in JavaScript represents an HTML element and allows you to create, manipulate, and load images dynamically without adding them directly to the HTML. Creating Image Objects You can create an Image object using the new Image() constructor, optionally specifying width and height: // Basic image creation let img = new Image(); // With dimensions let imgWithSize = new Image(300, 200); Properties The Image object has several important properties: src - Sets or gets the image URL width - Sets or ...

Read More

JavaScript outsider function call and return the result

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 227 Views

In JavaScript, you can call functions from outside their defining scope by using the return keyword to return inner functions. This creates closures that maintain access to outer variables. Syntax function outerFunction() { // Outer variables var outerVar = value; // Inner function var innerFunction = function() { // Can access outerVar return result; } ...

Read More

Finding special type of numbers - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 245 Views

In the decimal number system, all the real numbers can be divided into two groups: Rational Numbers Irrational Numbers For the scope of this problem we will only discuss the rational numbers. All those numbers which can be written in the p/q form (where q ≠ 0) are called rational numbers, like 14, 4.6, 3.33333... and many more. The rational numbers can further be divided into two groups: Terminating decimal numbers Repeating decimal numbers This categorization is made on the basis ...

Read More

JavaScript DataView()

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 241 Views

The JavaScript DataView provides a low-level interface for reading and writing multiple number types in binary ArrayBuffer. You cannot manipulate ArrayBuffer directly without using DataView(). Syntax new DataView(buffer) new DataView(buffer, byteOffset) new DataView(buffer, byteOffset, byteLength) Parameters buffer - The ArrayBuffer to create a view for byteOffset - (Optional) Starting byte offset, default is 0 byteLength - (Optional) Number of bytes to include, default is buffer's length Basic Example DataView Example Run ...

Read More

Converting a proper fraction to mixed fraction - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 545 Views

A proper fraction is one where the numerator is smaller than the denominator, represented in p/q form where both p and q are natural numbers. What is a Mixed Fraction? When we divide the numerator (a) of a fraction by its denominator (b), we get a quotient (q) and remainder (r). The mixed fraction form for fraction a/b is: Mixed form: q r b This is pronounced as "q wholes and r by b". Problem Statement We need to write a ...

Read More

Check whether a string ends with some other string - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 212 Views

In JavaScript, there are multiple ways to check if a string ends with another string. The most straightforward approach is using the built-in endsWith() method, though you can also implement custom solutions. Using String.endsWith() (Recommended) The endsWith() method is the standard way to check if a string ends with a specific substring: const str1 = 'this is just an example'; const str2 = 'ample'; console.log(str1.endsWith(str2)); // true console.log(str1.endsWith('temple')); // false console.log(str1.endsWith('example')); // true true false true Custom Implementation ...

Read More

Explain load events in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 848 Views

Load events in JavaScript are fired at different stages of the page lifecycle, from initial DOM construction to complete resource loading and page unloading. Understanding these events helps you execute code at the right time. Types of Load Events Event Description When It Fires DOMContentLoaded DOM tree is built but external resources like stylesheets and images are still loading HTML parsed completely load All resources (images, stylesheets, scripts) are fully loaded Page completely loaded beforeunload User is about to leave the page - can show confirmation dialog ...

Read More

Explain JavaScript text alert

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 261 Views

The JavaScript alert() function is used to display a popup message to the user. It's a built-in browser method that creates a modal dialog box with a message and an "OK" button. Syntax alert(message); Parameters The alert() function accepts one parameter: message - A string that specifies the text to display in the alert box Basic Example JavaScript Alert Example JavaScript Text ...

Read More
Showing 4501–4510 of 8,392 articles
« Prev 1 449 450 451 452 453 840 Next »
Advertisements