Front End Technology Articles

Page 334 of 652

How to format a rounded number to N decimals using JavaScript?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 524 Views

Use the toFixed() method to format a rounded number to N decimals. The toFixed() method formats a number with a specific number of digits to the right of the decimal point and returns a string representation. Syntax number.toFixed(digits) Parameters digits (optional): An integer specifying the number of digits after the decimal point. Must be in the range 0-100. Default is 0. Return Value Returns a string representation of the number with the specified number of decimal places. Example Here's how to format numbers to different decimal places: ...

Read More

How to format hexadecimal Number in JavaScript?

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

JavaScript provides several methods to format hexadecimal numbers. The most common approach is using toString(16) to convert numbers to hexadecimal format, then applying padding and formatting as needed. Basic Hexadecimal Conversion The toString(16) method converts a number to its hexadecimal representation: let num = 255; let hex = num.toString(16); document.write("Number: " + num + ""); document.write("Hexadecimal: ...

Read More

How I can replace a JavaScript alert pop up with a fancy alert box?

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 1K+ Views

Creating a custom fancy alert box gives you complete control over the design and user experience. Instead of the basic browser alert, you can create styled modal dialogs using HTML, CSS, and JavaScript. Using jQuery for Custom Alert Here's a complete example that replaces the standard JavaScript alert with a custom-styled modal: function functionAlert(msg, myYes) { var confirmBox = $("#confirm"); ...

Read More

What is the best way to initialize a JavaScript number?

Prabhas
Prabhas
Updated on 15-Mar-2026 824 Views

The best way to initialize a number in JavaScript is to assign a value during variable declaration. This approach prevents undefined values and ensures your variables are ready to use immediately. Basic Number Initialization You can initialize numbers using various declaration keywords: Number Initialization // Initialize with var var deptNum = 20; var employeeId = 5; // Note: ...

Read More

How to show image in alert box using JavaScript?

Nancy Den
Nancy Den
Updated on 15-Mar-2026 2K+ Views

JavaScript's default alert() function cannot display images. To show an image in an alert-like dialog, you need to create a custom modal dialog using HTML, CSS, and JavaScript. Why Default alert() Cannot Show Images The browser's built-in alert() function only accepts text strings. It cannot render HTML elements like images, making a custom solution necessary. Creating a Custom Image Alert Here's a complete example that creates a custom alert dialog with an image: ...

Read More

How do I display image in alert/confirm box in JavaScript?

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

In this tutorial, we will learn to display images in alert or confirm boxes in JavaScript. The standard alert() method displays a simple dialog box with text and an OK button, but it doesn't support images directly. To create more attractive and informative dialogs with images, we have two main approaches: Creating a custom alert box using vanilla JavaScript Using jQuery's dialog() method Method 1: Creating a Custom Alert Box This approach involves creating a custom HTML div that mimics an alert box and can contain images, styled ...

Read More

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

varun
varun
Updated on 15-Mar-2026 891 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 988 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 1K+ 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
Showing 3331–3340 of 6,519 articles
« Prev 1 332 333 334 335 336 652 Next »
Advertisements