Front End Technology Articles

Page 383 of 652

What is the importance of '+' operator in type conversion in JavaScript?

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 275 Views

JavaScript is a dynamically typed language where operations often automatically convert values to the appropriate type. The + operator plays a crucial role in type conversion, behaving differently depending on the operand types. JavaScript provides many ways to convert data from one form to another, with two most common types of conversion: Converting values to strings Converting values to numbers The '+' Operator's Dual Behavior The + operator in JavaScript serves two purposes: Addition: When both operands are numbers String ...

Read More

How to get the Width and Height of the screen in JavaScript?

Sai Teja Kotha
Sai Teja Kotha
Updated on 15-Mar-2026 10K+ Views

In this article, we are going to discuss how to get the width and height of the screen in JavaScript. JavaScript provides a window.screen object that contains information regarding the user's screen. The information includes height and width, and also many other features like color depth and pixel density. To find the height and width of the screen you need to use the following read-only properties: screen.height − This property returns the height of the screen in pixels. screen.width − This property returns the width of the screen in pixels. ...

Read More

Counting below / par elements from an array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 246 Views

We are required to write a function that counts how many elements in an array are below or at/above a given number. Following is our array of Numbers − const array = [54, 54, 65, 73, 43, 78, 54, 54, 76, 3, 23, 78]; For example, if the number is 60, there should be 7 elements below it − 54, 54, 43, 54, 54, 3, 23 and 5 elements at or above it − 65, 73, 78, 76, 78 Using Array.reduce() Method The reduce() method processes ...

Read More

How to modify an array value of a JSON object in JavaScript?

Sai Teja Kotha
Sai Teja Kotha
Updated on 15-Mar-2026 8K+ Views

In JavaScript, JSON objects are regular JavaScript objects that can contain arrays. Modifying array values within these objects is straightforward using array indexing or array methods. When working with JSON objects containing arrays, you can access and modify array elements just like you would with any JavaScript array, using bracket notation or array methods. Syntax To modify an array value in a JSON object: // Direct index assignment jsonObject.arrayProperty[index] = newValue; // Using array methods jsonObject.arrayProperty.push(newValue); jsonObject.arrayProperty.splice(index, 1, newValue); Method 1: Direct Index Assignment The simplest way to modify an array ...

Read More

How to concatenate two strings so that the second string must concatenate at the end of first string in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 1K+ Views

String concatenation is the process of joining two or more strings together to create a new string. In JavaScript, there are several methods to concatenate strings, with the second string being appended at the end of the first string. Using concat() Method The concat() method joins the calling string with the provided string arguments to create a new string. The original strings remain unchanged since strings in JavaScript are immutable. Syntax concat(str1) concat(str1, str2) concat(str1, str2, ... , strN) Parameters Parameter Description strN One or more strings to ...

Read More

What is the importance of str.padStart() method in JavaScript?

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

The padStart() method in JavaScript pads a string at the beginning to reach a specified length. It's particularly useful for formatting numbers, creating aligned text, and adding prefixes with consistent string lengths. Syntax string.padStart(targetLength, padString) Parameters targetLength: The desired length of the resulting string after padding. padString (optional): The string to use for padding. Defaults to a space character if not provided. Return Value Returns a new string padded at the beginning. The original string remains unchanged. Basic Example ...

Read More

Merging boolean array with AND operator - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 828 Views

Let's say, we have an array of arrays of boolean like this − const arr = [[true, false, false], [false, false, false], [false, false, true]]; We are required to write a function that merges this array of arrays into a one-dimensional array by combining the corresponding elements of each subarray using the AND (&&) operator. Let's write the code for this function. We will be using Array.prototype.reduce() function to achieve this. Example Following is the code − const arr = [[true, false, false], [false, false, false], [false, false, true]]; const ...

Read More

In how many ways can we find a substring inside a string in javascript?

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

JavaScript provides several methods to find a substring inside a string. The most commonly used approaches are indexOf(), includes(), search(), and regular expressions with match(). Using indexOf() Method Syntax string.indexOf(substring, startPosition) The indexOf() method returns the index of the first occurrence of the substring. If the substring is not found, it returns -1. This method is case-sensitive. Example var company = "Tutorialspoint"; document.write("Index of 'point': " + company.indexOf('point')); document.write(""); document.write("Is 'Tutor' present: " + (company.indexOf('Tutor') !== ...

Read More

How to get the code name and product name of the browser in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 554 Views

When a user accesses a web application, the JavaScript navigator object contains details about the browser they are currently using. Since each browser functions differently in how it interprets JavaScript, the navigator object helps in adapting your application to the user's browser preferences. The browser engine or product name can be accessed in JavaScript using the navigator.product property. However, in modern browsers, navigator.product always returns "Gecko" for compatibility reasons, regardless of the actual browser being used. Navigator.product Property Syntax navigator.product Example 1: Getting Browser Product Name This example demonstrates how to access ...

Read More

Prime numbers upto n - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 697 Views

Let's say, we are required to write a JavaScript function that takes in a number, say n, and returns an array containing all the prime numbers up to n. For example − If the number n is 24, then the output should be − const output = [2, 3, 5, 7, 11, 13, 17, 19, 23]; Method 1: Basic Prime Check Approach This approach uses a helper function to check if each number is prime: const num = 24; const isPrime = num => { let count ...

Read More
Showing 3821–3830 of 6,519 articles
« Prev 1 381 382 383 384 385 652 Next »
Advertisements