Function for finding roots in JavaScript: 1. sqrt() function, syntax "Math.sqrt(x)", which can calculate the square root of the number x; 2. pow() function, syntax "Math.pow( x,(1/y))", can calculate the y-th root of the number x.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
javascript root finding
1. Use the sqrt() function
sqrt() method Returns the square root of a number.
Syntax:
Math.sqrt(x)
Example:
var x=9; console.log(Math.sqrt(x));
Output result:
2. Use the pow() function
Math.pow(x,y)
can raise the y power of x. When y is a decimal (1/y), it can be used for root calculation.
function f(x,y){ y=1/y; console.log(Math.pow(x,y)); } f(4,2); f(125,3); f(81,4);
【Related recommendations: javascript learning tutorial】
The above is the detailed content of What are the functions for finding roots in javascript?. For more information, please follow other related articles on the PHP Chinese website!