Found 6710 Articles for Javascript

How to change button label in confirm box using JavaScript?

Shubham Vora
Updated on 02-Aug-2022 11:29:10

14K+ Views

In this tutorial, we will learn to change the button label in the confirm box using JavaScript. The confirm box is useful for taking the confirmation from the user. For example, when you try to delete something from your account on some websites, they show you a popup box containing a message like “Are you sure to delete ….?”. Also, it contains the yes and no buttons, which is one kind of confirmation the application takes from the users. JavaScript users can create the confirm box using the .confirm() method, which contains the confirmation message string, ok, and cancel button. ... Read More

How can I remove the decimal part of JavaScript number?

Shubham Vora
Updated on 06-Sep-2023 10:51:38

46K+ Views

In this tutorial, we will learn to remove the decimal part of the number in JavaScript. While working with JavaScript, many times, developers need to play with the numbers stored in the database and needs to convert float and double numbers into the pure decimal or integer number.In this situation, developers can have multiple methods to truncate the decimal part of the number. We will see different approaches to overcome the above problem.Using the Math.trunc() methodUsing the Bitwise operatorsUsing the Math.ceil() and Math.floor() methodUsing the Math.Trunc() methodThe Math.trunc() is the most popular method to remove the decimal part of JavaScript. ... Read More

What is the best way to convert a number to a string in JavaScript?

vanithasree
Updated on 17-Jun-2020 06:37:14

218 Views

The best way to convert a number to a string is using the toString() method, with different bases. The method has an optional parameter “radix”, which is used as a base (2, 8, 16) for a numeric value.ExampleYou can try to run the following code to convert a number to a string −Live Demo                    var num = 10;          var val1 = num.toString();          var val2 = num.toString(2);          var val3 = num.toString(8);          var val4 = num.toString(16);          document.write(val1 + "" + val2 + "" + val3 + "" + val4);           Output10 1010 12 a

How to pad a number with leading zeros in JavaScript?

Shubham Vora
Updated on 06-Sep-2023 10:20:39

69K+ Views

In this tutorial, we will learn how to pad a number with leading zeros in JavaScript. Padding a number can be done in different ways in JavaScript. In this tutorial, we will see the two most popular ways of doing it − Using the String padStart() method Using the Array object constructor and join() method Using the String padStart() Method In JavaScript, the String object’s padStart() method is useful to pad a number with leading zeros. It takes two parameters, the first one is the total length of the targeted or desired string, and the other one is ... Read More

How to get a decimal portion of a number with JavaScript?

mkotla
Updated on 17-Jun-2020 06:35:57

3K+ Views

With JavaScript, use the % operator to get the decimal portion of a number.ExampleYou can try to run the following to get decimal portion −Live Demo                    var num1 = 5.3;          var num2 = 4.2;          var num3 = 8.6;          document.write(num1 % 1);          document.write(""+num2 % 1);          document.write(""+num3 % 1);           Output0.2999999999999998 0.20000000000000018 0.5999999999999996

How to check whether a checkbox is checked in JavaScript?

Shubham Vora
Updated on 06-Sep-2023 14:13:45

53K+ Views

In this tutorial, we will learn to check whether a checkbox is checked in JavaScript. The checkbox is the input type in the HTML, which works as the selection box. The radio buttons which belong to the same group allow users to select only one value. Still, the checkbox which belongs to the same group allows users to select multiple values. Also, you have many uses of checkboxes in your mind yourself. The HTML can add a checkbox to the webpage, but to add the behaviour to the checkbox, we must use JavaScript. Programmers can add different behaviours to the ... Read More

How to Delete Bookmarks in your Browser (Firefox, Chrome)

Rahul Sharma
Updated on 15-Jun-2020 08:51:40

263 Views

Bookmarks in a web browser are saved so that it can be referred. It is also known as favorite web pages. To Bookmark a web page, visit the page and press Ctrl+D. This will give you an option to save the web page.In this way, all the bookmarks get saved like this on pressing Ctrl+D. The star sign as you can see below also allows you to add a bookmark −Bookmark on FirefoxBookmark on ChromeLet’s learn how to delete a bookmark in a web browser. To delete a bookmark, which you bookmarked before in Firefox or Chrome, you need to ... Read More

How to format hexadecimal Number in JavaScript?

Giri Raju
Updated on 17-Jun-2020 06:35:28

2K+ Views

Firstly convert your number to hexadecimal with leading zeros and then format it by adding dashes.ExampleYou can try to run the following code to format hexadecimal number −Live Demo                    var num = 32122;          var myHex = ("000000000000000" + num.toString(16)).substr(-16);          var resHex = myHex.substr(0, 8)+'-'+myHex.substr(8,4)+'-'+myHex.substr(12,4);          document.write(resHex);           Output00000000-0000-7d7a

How to change Firefox Browser theme?

Johar Ali
Updated on 15-Jun-2020 08:44:18

365 Views

Firefox web browser is widely used and loved by many users around the world. Well, you can easily change the Firefox Browser theme and make it look more awesome.Let’s see how to reach the Firefox theme section and change the theme −Open Firefox MenuGo to the following section and click to open the Firefox browser menu. After that, you need to click Add-ons:AppearanceTo reach the Themes section, click on Add-ons and then click on Appearance as shown below −On clicking Appearance, the themes will be visible. Click Enable to enable any theme or choose from thousands of other themes as ... Read More

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

Anvi Jain
Updated on 17-Jun-2020 06:45:36

461 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.ExampleYou can try to run the following code to form a rounded number to N decimals −Live Demo           JavaScript toFixed() Method                        var num = 15;          document.write("num.toFixed() is : " + num.toFixed());          document.write("");          document.write("num.toFixed() is : " + num.toFixed(2));          document.write("");          document.write("num.toFixed() is : " + num.toFixed(1));          document.write("");           Outputnum.toFixed() is : 15 num.toFixed() is : 15.00 num.toFixed() is : 15.0

Advertisements