Object Oriented Programming Articles

Page 107 of 589

How to make Format ABC-1234 in JavaScript regular Expressions?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 358 Views

In JavaScript, you can format strings to match the pattern ABC-1234 using regular expressions. This pattern consists of three uppercase letters followed by a dash and four digits. Understanding the Pattern The ABC-1234 format requires: Three uppercase letters (A-Z) A dash (-) Four digits (0-9) Regular Expression Pattern The regex pattern for ABC-1234 format is: /^[A-Z]{3}-\d{4}$/ Breaking down this pattern: ^ - Start of string [A-Z]{3} - Exactly 3 uppercase letters - - Literal dash character \d{4} - Exactly 4 digits $ - End of string Method ...

Read More

JavaScript code for recursive Fibonacci series

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 428 Views

We have to write a recursive function fibonacci() that takes in a number n and returns an array with first n elements of fibonacci series. The Fibonacci sequence starts with 0 and 1, where each subsequent number is the sum of the two preceding ones. Understanding the Fibonacci Sequence The Fibonacci sequence follows this pattern: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34... where F(n) = F(n-1) + F(n-2). Recursive Implementation Here's a recursive approach that builds the Fibonacci array: const fibonacci = (n, res = [], count = 1, last = ...

Read More

The onchange event is not working in color type input with JavaScript

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

The onchange event works perfectly with color input elements in JavaScript. When a user selects a different color, the event triggers automatically, allowing you to capture and process the new color value. Syntax Basic Example Color Input onchange Event Choose Color: ...

Read More

Recursive product of summed digits JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 239 Views

We need to create a function that takes multiple numbers as arguments, adds them together, then repeatedly multiplies the digits of the result until we get a single digit. Problem Breakdown For example, with arguments 16, 34, 42: 16 + 34 + 42 = 92 Then multiply digits until single digit: 9 × 2 = 18 1 × 8 = 8 (final result) Solution Approach We'll break this into two helper functions: produce() - calculates the product of digits in a number using ...

Read More

Get value from div with JavaScript resulting undefined?

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

When trying to get the value from a div element using JavaScript, you might encounter undefined results if you use incorrect properties. The key is understanding the difference between innerHTML, textContent, and value. The Problem The most common mistake is using .value on div elements. The value property only works for form inputs like , , and . For div elements, use innerHTML or textContent. Using innerHTML innerHTML gets the HTML content inside the element, including any HTML tags: Get Div Value ...

Read More

How to override derived properties in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 399 Views

In JavaScript, when an object inherits properties from its prototype, you can override those inherited properties by assigning new values directly to the child object. This creates own properties that shadow the prototype properties. Understanding Property Inheritance When you create an object using Object.create(), the new object inherits properties from its prototype. These inherited properties can be overridden by setting properties directly on the derived object. Example: Overriding Derived Properties Override Derived Properties ...

Read More

Loop through array and edit string JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 813 Views

Let's say, we have to write a function, say translate() that accepts a string as the first argument and any number of words after that. The string will actually contain n $ signs like this − This $0 is more $1 just a $2. Then there will be 3 strings which will replace the corresponding places. For example − If the function call is like this: translate('This $0 is more $1 just a $2.', 'game', 'than', 'game'); The output of the function should be: This game is more ...

Read More

Looping over matches with JavaScript regular expressions

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 958 Views

In JavaScript, you can loop over regular expression matches using several methods. The most common approaches are using match() with the global flag, matchAll(), or exec() in a loop. Using match() with Global Flag The match() method with the global flag (g) returns an array of all matches, which you can then iterate over: Regex Matches Loop body { ...

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

Explain load events in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 847 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
Showing 1061–1070 of 5,881 articles
« Prev 1 105 106 107 108 109 589 Next »
Advertisements