Found 10878 Articles for Web Development

Regular expression to match numbers only in JavaScript?

Shubham Vora
Updated on 15-Nov-2022 09:22:47

4K+ Views

In this tutorial, we will learn regular expressions to match numbers only in JavaScript. Data is a core element in every webpage. We have to validate it as per the requirements. We often deal with the data and require correct input from the user. For example, the user can not put the letters inside the field to accept the phone number, or the input length should be ten numbers. To validate the data in JavaScript, regular expression is used. We often need to filter the necessary data and extract the matched data. Here, we are going to match all the ... Read More

How to get the current time in millisecond using JavaScript?

Sravani S
Updated on 19-Jun-2020 08:49:02

1K+ Views

To get the current time in a millisecond, use the date getMilliseconds() method. JavaScript date getMilliseconds() method returns the milliseconds in the specified date according to local time. The value returned by getMilliseconds() is a number between 0 and 999.Example You can try to run the following code to get the current time in milliseconds −           JavaScript getMilliseconds() Method                        var dt = new Date( );          document.write("getMilliseconds() : " + dt.getMilliseconds() );          

How to convert a JavaScript date object to a string?

Shubham Vora
Updated on 17-Aug-2022 12:31:21

12K+ Views

In this tutorial, we will learn to convert JavaScript date objects to a string. In JavaScript, we can invoke some methods on the string only. So, we need to convert the date to the string to use the date with such methods. Here, we have three different approaches to converting the date object to a string. Using the toString() Method In this approach, we will use the toString() method of JavaScript to convert the date object to a string. The toString() method is useful to convert the variable of any data type such as number, objects, or array to string. ... Read More

How to get the value of a number rounded to the nearest integer in JavaScript?

Shubham Vora
Updated on 14-Sep-2022 09:00:14

900 Views

In this tutorial, we will learn how to get the value of a number rounded to the nearest integer in JavaScript. The nearest integer of a number can be found in different ways in JavaScript. In this tutorial, we will see the two most popular ways of doing it− Using Math.round() method Without using the Math.round() method Rounding a number means taking the nearest integer value from that number. It is useful for mathematical calculations when you need an approximate value to simplify your calculation. For example: If you have a number like 0.9999999, then taking this number ... Read More

How to get the exponent power of a number in JavaScript?

Shubham Vora
Updated on 26-Aug-2022 13:04:14

4K+ Views

In this tutorial, we will learn how to get the exponent power of a number in JavaScript. The power of a number can be termed as how many times a particular number is multiplied by the number itself. For calculating the power of a number, we require two things, Base and Exponent. At the same time, a Base is a number that must be multiplied. Exponent (Usually written in the superscript) determines the number of times the number (Base) should be multiplied by itself. While we represent the power of a number using "^" or superscript when typing it, we ... Read More

How to calculate the area and perimeter of a circle in JavaScript?

radhakrishna
Updated on 19-Jun-2020 08:46:31

709 Views

To calculate the area and perimeter of a circle, you can try to run the following code −Example           JavaScript Example                        function Calculate(r) {             this.r = r;             this.perimeter = function () {                return 2*Math.PI*this.r;             };             this.area = function () {                return Math.PI * this.r * this.r;             };          }                    var calc = new Calculate(5);                    document.write("Area of Circle = ", calc.area().toFixed(2));          document.write("Perimeter of Circle = ", calc.perimeter().toFixed(2));          

How to create RegExp object in JavaScript?

Priya Pallavi
Updated on 19-Jun-2020 08:46:00

105 Views

A regular expression is an object that describes a pattern of characters. The JavaScript RegExp class represents regular expressions, and both String and RegExp define methods that use regular expressions to perform powerful pattern-matching and search-and-replace functions on the text.A regular expression could be defined with the RegExp () constructor, as follows −var pattern = new RegExp(pattern, attributes); or simply var pattern = /pattern/attributes;The following are the parameters −pattern − A string that specifies the pattern of the regular expression or another regular expression.attributes − An optional string containing any of the "g", "i", and "m" attributes that specify global, ... Read More

How to convert a negative number to a positive one in JavaScript?

Shubham Vora
Updated on 10-Aug-2022 11:56:39

11K+ Views

This tutorial will teach us to convert negative numbers to positive ones. Sometimes, programmers need to perform some operation with the unsigned value of the number, and in such a case, they need to convert the negative numbers to positive numbers. We will go through the various methods to convert a negative number to a positive number in this tutorial. Using the Math.abs() Method Multiplying the negative number with -1 Using the Bitwise Not Operator Using the Math.abs() Method The Math.abs() method is the JavaScript math library method. The Math.abs() method takes a value as a parameter and ... Read More

How to do basic Maths with JavaScript Operators?

Shubham Vora
Updated on 23-Aug-2022 09:05:28

148 Views

In this guide, we will explain the different methods to do basic maths with JavaScript operators. While creating any website, application, or game, you might have to show the calculated results, whether the number shows the subscriber count or the points of the user. Hence, learning how to add, subtract, and multiply using different data types in JavaScript is important. Using (+) Operator for Addition in JavaScript The binary operator to do basic maths in JavaScript is straightforward. However, the process can become a bit complex when you have to get the number as the output. This method will teach ... Read More

What are JavaScript Math Functions?

Nishtha Thakur
Updated on 19-Jun-2020 08:27:12

302 Views

The following are some of the Math Functions in JavaScript −S.NoMethod & Description 1abs()Returns the absolute value of a number.2acos()Returns the arccosine (in radians) of a number.3asin()Returns the arcsine (in radians) of a number.4atan()Returns the arctangent (in radians) of a number.5atan2()Returns the arctangent of the quotient of its arguments.6ceil()Returns the smallest integer greater than or equal to a number.ExampleLet’s see an example of abs() Math function in JavaScript. The Math() function returns the absolute value of a number −           JavaScript Math abs() Method                        var ... Read More

Advertisements