Web Development Articles

Page 429 of 801

Vowel, other characters and consonant difference in a string JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 244 Views

We are required to write a function that takes in a string of definite characters and the function should return the difference between the count of vowels plus other characters and consonants in the string. Problem Explanation For example, if the string is: "HEllo World!!" Then, we have 7 consonants, 3 vowels and 3 other characters here so the output should be: |7 - (3+3)| = 1 Hence, the output should be 1 Example const str = 'HEllo World!!'; const findDifference = str => { const creds ...

Read More

Explain the callback Promise.finally in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 256 Views

The Promise.finally() method executes a callback function when a promise settles, regardless of whether it's fulfilled or rejected. This method is essential for cleanup operations and tasks that must run after promise completion. Syntax promise.finally(callback) Parameters callback: A function that executes when the promise settles. It receives no arguments and its return value is ignored. How It Works Unlike .then() and .catch(), the finally callback doesn't receive the promise's result or rejection reason. It simply indicates that the promise has completed. Example with Fetch API ...

Read More

Return the difference between the maximum & minimum number formed out of the number n in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 429 Views

We have to write a function that takes a positive number n and returns the difference between the maximum number and the minimum number that can be formed from its digits. For example, if the number n is 203: The maximum number that can be formed from its digits will be 320 The minimum number that can be formed from its digits will be 23 (placing the zero at one's place) And the difference will be: 320 - 23 = 297 Therefore, the output should ...

Read More

Explain 'dotAll' flag for regular expressions in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 309 Views

The dotAll flag returns true or false depending upon if the s flag has been set in the regular expression. The s flag enables "dotAll" mode, where the dot . metacharacter matches any character, including newlines. What is the dotAll Flag? By default, the dot . in regular expressions matches any character except newlines. When the s flag is used, the dot can also match newline characters (, \r, etc.), making it truly match "any" character. Syntax regex.dotAll // Returns true if 's' flag is set, false otherwise Example: Checking dotAll Flag ...

Read More

Return Top two elements from array JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 379 Views

We have an array of numbers in JavaScript that contains numbers in an unsorted order. Our job is to write a function that takes in this array of numbers and returns an array of two elements, the top two elements of the array (greatest two elements of the array). We have to do this in one pass i.e., we need to execute this method in linear time like by using only one for loop or if we use ES6 function, we have to make sure to use only one and once and avoid nesting of methods which increases time ...

Read More

How to import and export a module/library in JavaScript?

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

Note − To run this example you will need to run a localhost server. JavaScript modules allow you to break code into separate files and share functionality between them using export and import statements. This promotes code reusability and better organization. Example INDEX.html Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; ...

Read More

NaN and Infinity example in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 271 Views

In JavaScript, NaN (Not-a-Number) and Infinity are special numeric values that represent invalid or infinite calculations. Understanding these values is crucial for handling mathematical operations and validation. What is NaN? NaN represents a value that is "Not-a-Number". It occurs when a mathematical operation fails or produces an undefined result. NaN Examples let results = document.getElementById('nanResults'); ...

Read More

Reverse all the words of sentence JavaScript

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

We are required to write a JavaScript function that takes in a string and returns a new string which has all the words reversed from the original string. For example − If the original string is − "Hello World how is it outside" Then the output should be − "olleH dlroW woh si ti edistuo" Now, let's write the code for this function − Example const str = 'Hello World how is it outside'; const reverseSentence = str => { const arr = ...

Read More

How to search for a string in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 317 Views

JavaScript provides several methods to search for strings. The most common approaches are search(), indexOf(), includes(), and match(). Using search() Method The search() method returns the index of the first match or -1 if not found. It supports regular expressions. String Search Example The spring season is about to come. SEARCH FOR 'spring' ...

Read More

How to print positive and negative infinity values in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 283 Views

In JavaScript, infinity values represent numbers that exceed the maximum finite value. JavaScript provides built-in constants to handle positive and negative infinity values. JavaScript Infinity Constants JavaScript has two built-in constants for infinity values: Infinity or Number.POSITIVE_INFINITY - represents positive infinity -Infinity or Number.NEGATIVE_INFINITY - represents negative infinity Basic Example JavaScript Infinity Values JavaScript Infinity Values ...

Read More
Showing 4281–4290 of 8,010 articles
« Prev 1 427 428 429 430 431 801 Next »
Advertisements