Javascript Articles

Page 409 of 534

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

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 271 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

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 234 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

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

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 181 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 546 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

How to get the protocol and page path of the current web page in JavaScript?

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

In JavaScript, you can retrieve both the protocol (like https:// or http://) and the page path of the current webpage using the window.location object and URL constructor. These properties are essential for web development tasks like URL manipulation and navigation. Getting the Protocol The protocol specifies the data transfer method used by the URL. Use window.location.protocol or URL.protocol to retrieve it. Syntax protocol = window.location.protocol; // or protocol = new URL(url).protocol; Using window.location.protocol Protocol Example ...

Read More

How to return an array whose elements are the enumerable property values of an object in JavaScript?

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

We can use various methods to get values and keys from an object, but those methods will not return the values as an array, which is very useful in many cases. JavaScript provides the Object.values() method to get an array whose elements are the enumerable property values of an object. Syntax Object.values(obj); This method takes an object as an argument and returns an array whose elements are the property values of the object. Parameters obj: The object whose enumerable property values are to be returned. Return Value An array containing the ...

Read More

How to get the pixel depth and color depth of a screen in JavaScript?

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

The JavaScript window object provides methods to get screen display information through the screen object. Two important properties are screen.colorDepth and screen.pixelDepth which return the color depth and pixel depth of the browser screen respectively. Color Depth The screen.colorDepth property returns the number of bits used to display one color on the screen. Modern computers typically use 24-bit or 32-bit hardware for color resolution, where: 24-bit color: Supports 16.7 million colors (True Color) 32-bit color: Includes an alpha channel for transparency Syntax screen.colorDepth Example ...

Read More
Showing 4081–4090 of 5,340 articles
« Prev 1 407 408 409 410 411 534 Next »
Advertisements