Home  >  Article  >  Web Front-end  >  Does javascript have a root function?

Does javascript have a root function?

青灯夜游
青灯夜游Original
2022-03-28 18:52:165239browse

Javascript has a root function. In JavaScript, you can use the sqrt() function to find the square root, the syntax is "Math.sqrt(x)"; you can also use the pow() function to find the root of a specified power, the syntax is "pow(x,1/y) ”, which means opening the y-th root of x.

Does javascript have a root function?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Javascript has a root function.

In javascript, you can use the following function to open the root:

  • sqrt() function

  • pow() function

1. Use the sqrt() function to open the root number

The sqrt() method can return the square root of a number.

This function does not support negative numbers. If the parameter is less than 0, it returns NaN.

Example:

<script>
	console.log(Math.sqrt(1));
	console.log(Math.sqrt(4));
	console.log(Math.sqrt(9));
	console.log(Math.sqrt(64));
	console.log(Math.sqrt(-9));
</script>

Does javascript have a root function?

1. Use the pow() function to open the root

pow(x,y) can return x raised to the y power.

When the parameter y is a fraction (greater than 0, less than 1), that is, pow(x,1/y) can open the y-th root of x.

Example:

<script>
	console.log(Math.pow(4,1/2));
	console.log(Math.pow(81,1/4));
	console.log(Math.pow(256,1/4));
</script>

Does javascript have a root function?

[Related recommendations: javascript video tutorial, web front-end]

The above is the detailed content of Does javascript have a root function?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn