Front End Technology Articles

Page 391 of 652

w vs W in JavaScript regex?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 4K+ Views

In JavaScript regex, \w and \W are complementary metacharacters used to match different types of characters. \w matches word characters (letters, digits, and underscores), while \W matches non-word characters (everything else). Understanding \w Metacharacter The \w metacharacter is equivalent to [a-zA-Z0-9_], matching any single letter (uppercase or lowercase), digit, or underscore. Syntax // Using RegExp constructor RegExp("\w", "g") // Using literal notation /\w/g Example: Using \w to Match Word Characters \w vs \W in JavaScript regex \w Metacharacter Example ...

Read More

d vs D in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 3K+ Views

In JavaScript regular expressions, \d and \D are metacharacters used to match different types of characters in strings. Understanding their differences is essential for effective pattern matching. \d matches any single digit character (equivalent to [0-9]), while \D matches any character that is NOT a digit (equivalent to [^0-9]). These metacharacters are complete opposites of each other. Syntax Both metacharacters can be used in two ways: // Using RegExp constructor new RegExp("\d", "g") // matches digits new RegExp("\D", "g") // matches non-digits // Using regex literal /\d/g ...

Read More

Square every digit of a number - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 490 Views

We are required to write a JavaScript function that takes in a number and returns a new number in which all the digits of the original number are squared and concatenated. For example: If the number is − 9119 Then the output should be − 811181 because 9² is 81 and 1² is 1. Example Following is the code − const num = 9119; const squared = num => { const numStr = String(num); let res = ''; ...

Read More

Regular functions vs Arrow functions in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 655 Views

Arrow functions and regular functions are both ways to define functions in JavaScript, but they have important differences in behavior. Understanding these differences helps you choose the right function type for your needs. Syntax The syntax differs between regular and arrow functions: Arrow Function Syntax let x = (params) => { // code }; Regular Function Syntax let x = function functionName(params) { // code }; Usage of "this" Keyword The most significant difference is how they handle the this ...

Read More

Sorting Array with JavaScript reduce function - JavaScript

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

We are required to write a JavaScript function that takes in an array of numbers. The function should sort the array without using the Array.prototype.sort() method. We are required to use the Array.prototype.reduce() method to sort the array. Let's say the following is our array: const arr = [4, 56, 5, 3, 34, 37, 89, 57, 98]; Understanding the Approach The reduce() method can be used to build a sorted array by iterating through each element and placing it in the correct position within an accumulator array. We'll use insertion sort logic within the ...

Read More

Trying to get number for each character in string - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 268 Views

We are required to write a JavaScript function that takes in a string. It should print out each number for every corresponding letter in the string. For example, a = 1 b = 2 c = 3 d = 4 e = 5 . . . Y = 25 Z = 26 Therefore, if the input is "hello man", Then the output should be a number for each character − "8, 5, 12, 12, 15, 13, 1, 14" How It Works The solution uses the charCodeAt() method to get ...

Read More

Working with forms in React.js

Shyam Hande
Shyam Hande
Updated on 15-Mar-2026 511 Views

In simple HTML forms, form elements maintain their values internally and submit when the form submission button is clicked. React provides a more controlled approach to handling forms through controlled components. HTML Form Example Form Example User Name: ...

Read More

How to replace leading zero with spaces - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 381 Views

We are required to write a JavaScript function that takes in a string that represents a number. Replace the leading zero with spaces in the number. We need to make sure the prior spaces in number are retained. For example, If the string value is defined as − " 004590808" Then the output should come as − " 4590808" Example Following is the code − const str = ' 004590808'; const replaceWithSpace = str => { let replaced = ''; const regex = new RegExp(/^\s*0+/); ...

Read More

Return 5 random numbers in range, first number cannot be zero - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 198 Views

We are required to write a JavaScript function that generates an array of exactly five unique random numbers. The condition is that all the numbers have to be in the range [0, 9] and the first number cannot be 0. Example Following is the code − const fiveRandoms = () => { const arr = [] while (arr.length < 5) { const random = Math.floor(Math.random() * 10); if (arr.indexOf(random) > -1){ ...

Read More

Validating email and password - JavaScript

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

Suppose, we have this dummy array that contains the login info of two of many users of a social networking platform − const array = [{ email: 'usman@gmail.com', password: '123' }, { email: 'ali@gmail.com', password: '123' }]; We are required to write a JavaScript function that takes in an email string and a password string. The function should return a boolean based on the fact whether or not the user exists in the database. Example Following is the code − ...

Read More
Showing 3901–3910 of 6,519 articles
« Prev 1 389 390 391 392 393 652 Next »
Advertisements