Front End Technology Articles

Page 221 of 652

How to count the number of occurrences of a character in a string in JavaScript?

varun
varun
Updated on 15-Mar-2026 866 Views

There are several methods to count character occurrences in a JavaScript string. Here are the most effective approaches: Using a For Loop The traditional method uses a simple for loop to iterate through each character: function countCharacter(str, char) { let count = 0; for (let i = 0; i < str.length; i++) { ...

Read More

How to convert a decimal number to roman using JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 919 Views

Roman numerals are a number system that uses letters from the Latin alphabet to represent values. In this tutorial, you'll learn how to convert decimal numbers to Roman numerals using JavaScript. Roman Numeral Symbols Seven basic symbols form Roman numerals: I = 1 V = 5 X = 10 L = 50 C = 100 D = 500 M = 1000 Additionally, subtractive combinations are used for specific values: IV = 4 IX = 9 XL = 40 XC = 90 CD = 400 CM = 900 Algorithm The ...

Read More

How to deal with floating point number precision in JavaScript?

varma
varma
Updated on 15-Mar-2026 971 Views

Floating point precision issues occur when JavaScript cannot exactly represent certain decimal numbers in binary format. Common problems include 0.1 + 0.2 = 0.30000000000000004. JavaScript provides several methods to handle these precision issues. The Floating Point Problem JavaScript uses IEEE 754 double-precision floating-point format, which can cause unexpected results: console.log(0.1 + 0.2); // 0.30000000000000004 console.log(0.1 + 0.2 === 0.3); // false ...

Read More

How to split JavaScript Number into individual digits?

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

In this tutorial, we will learn how to split a JavaScript number into individual digits. This technique is useful for tasks like checking palindrome numbers, finding digit sums, or analyzing number patterns. We'll explore three different approaches based on the input format: Using modulo operator for numeric input Using array push() method for string input Using string split() method for string input Method 1: Using Modulo Operator (Numeric Input) When the input is a number, we can use the modulo (%) operator with division to extract digits from right to left. Syntax ...

Read More

How to test if a JavaScript cookie has expired?

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

To test if a JavaScript cookie has expired, you need to check if the cookie exists or returns null. When a cookie expires, the browser automatically removes it, so attempting to access it will return null or undefined. Using document.cookie (Vanilla JavaScript) The most straightforward approach is to create a helper function that checks if a cookie exists: function getCookie(name) { const cookies = document.cookie.split(';'); for (let cookie of cookies) { const [cookieName, cookieValue] = cookie.trim().split('='); ...

Read More

How I can set the width and height of a JavaScript alert box?

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 4K+ Views

JavaScript's native alert() function creates a browser-controlled dialog box whose size cannot be customized. To set the width and height of an alert box, you need to create a custom alert dialog using HTML, CSS, and JavaScript. Why Native alert() Cannot Be Resized The browser's built-in alert() function creates a modal dialog with fixed dimensions determined by the browser and operating system. These native alerts cannot be styled or resized using CSS or JavaScript. Creating a Custom Alert Box Here's how to create a customizable alert box with specific width and height dimensions using jQuery: ...

Read More

How I can show JavaScript alert box in the middle of the screen?

Giri Raju
Giri Raju
Updated on 15-Mar-2026 2K+ Views

The native JavaScript alert() box cannot be repositioned as its styling and position are controlled by the browser. To show an alert box in the center of the screen, you need to create a custom alert dialog using HTML, CSS, and JavaScript. Why Native alert() Can't Be Centered The built-in alert() function displays a browser-controlled modal that appears at a fixed position determined by the browser, typically near the top of the viewport. This position cannot be customized through CSS or JavaScript. Creating a Custom Centered Alert Box Here's how to create a custom alert that ...

Read More

How to customize the position of an alert box using JavaScript?

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

To customize the position of an alert box, you need to create a custom alert since the native JavaScript alert() function cannot be positioned. We can build a custom alert box using HTML, CSS, and JavaScript, then control its position using CSS properties like top and left. Creating a Custom Alert Box The native alert() box position is controlled by the browser and cannot be customized. Instead, we create a custom modal dialog that mimics an alert box behavior. Example: Custom Positioned Alert Here's how to create a custom alert box with customizable positioning: ...

Read More

How to center the JavaScript alert message box?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 10K+ Views

In this tutorial, we will learn to center the JavaScript alert box. In JavaScript, an alert box is useful to show users some message, information, warning, success, etc. Let's understand it by real-world example when you open any website on the web browser and start to authenticate by entering your username and password. When you click the submit button, it gives a message in an alert box like the password should be 8 or more characters, or sign in successfully. Users can create the alert box using JavaScript's alert() method. Unfortunately, the default alert box doesn't allow us to ...

Read More

What is the difference between void, eval, and the Function constructor in JavaScript?

usharani
usharani
Updated on 15-Mar-2026 432 Views

JavaScript provides three distinct features for executing and manipulating code: void, eval(), and the Function constructor. Each serves different purposes and has unique characteristics. The void Operator The void operator evaluates an expression and always returns undefined. It's commonly used to prevent unwanted return values or create undefined values explicitly. Syntax void expression void(expression) Example // Basic void usage console.log(void 0); ...

Read More
Showing 2201–2210 of 6,518 articles
« Prev 1 219 220 221 222 223 652 Next »
Advertisements