Found 6710 Articles for Javascript

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

1K+ 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

222 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

13K+ 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

287 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

436 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

How to get the tangent of a number in JavaScript?

Shubham Vora
Updated on 14-Sep-2022 08:50:08

477 Views

In this tutorial, we will learn how to get the tangent of a number in JavaScript. The tangent of an angle is defined by the ratio of the length of the opposite side to the length of the adjacent side. It can also be defined as the ratio of sine and cosine function of an acute angle where the value of cosine function should not be zero. Mathematically, 𝑡𝑎𝑛𝜃=𝑙𝑒𝑛𝑔𝑡ℎ 𝑜𝑓 𝑡ℎ𝑒 𝑜𝑝𝑝𝑜𝑠𝑖𝑡𝑒 𝑠𝑖𝑑𝑒 / 𝑙𝑒𝑛𝑔𝑡ℎ 𝑜𝑓 𝑡ℎ𝑒 𝑎𝑑𝑗𝑎𝑐𝑒𝑛𝑡 𝑠𝑖𝑑𝑒 also, tanθ=(𝑠𝑖𝑛𝑒 𝑜𝑓 𝑡ℎ𝑒 𝑎𝑛𝑔𝑙𝑒 𝜃)⁄(𝑐𝑜𝑠𝑖𝑛𝑒 𝑜𝑓 𝑡ℎ𝑒 𝑎𝑛𝑔𝑙𝑒 𝜃) Where 𝜃 = acute angle in radian The tangent of ... Read More

How to get the square root of a number in JavaScript?

Shubham Vora
Updated on 31-Oct-2022 08:55:03

11K+ Views

In this tutorial, we will learn how to get the square root of a number in JavaScript in both ways. The square root of a number in JavaScript can be found in two ways − Using Math.sqrt() Method By creating a Custom Function The square root of a number is a factor that, when multiplied by itself, gives the original number. For example, 10 is the square root of 100 because if you multiply 10 by itself (10*10), the result will be 100. Using the Math.sqrt() Method In JavaScript, The Math.sqrt() method is useful for finding the square ... Read More

How to get the sine of a number in JavaScript?

Smita Kapse
Updated on 19-Jun-2020 07:54:06

232 Views

To get the sine of a number, use the JavaScript sine() technique. The sin technique returns a numeric value between -1 and one, that represents the sine of the argumentExampleYou can try to run the following code to get the sine of a number in JavaScript −           JavaScript Math sin() Method                        var value = Math.sin( 0.5 );          document.write("First Value : " + value );                    var value = Math.sin( 90 );          document.write("Second Value : " + value );          

How to get a pseudo-random number between 0 and 1 in JavaScript?

usharani
Updated on 19-Jun-2020 07:53:05

414 Views

To get a pseudo-random number between 0 and 1, use the Math.random() method in JavaScript.ExampleYou can try to run the following code to get a pseudo-random number between 0 and 1 −           JavaScript Math random() Method                        var value = Math.random( );          document.write("First Value : " + value );          value = Math.random( );          document.write("Second Value : " + value );          

Advertisements