Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,890 questions

51,819 answers

573 users

How to calculate exponent (base raised to the power of exp) (power function) in JavaScript

2 Answers

0 votes
console.log(Math.pow(2, 3));  // 8
console.log(Math.pow(3, 3));  // 27
console.log(Math.pow(3, 2));  // 9
console.log(Math.pow(2, 2));  // 4
console.log(Math.pow(5, 2));  // 25
 
 
 
 
/*
run:
 
8
27
9
4
25
 
*/

 



answered Jun 26, 2015 by avibootz
edited May 30, 2022 by avibootz
0 votes
<!DOCTYPE html>
<html>
<head>  
</head>
 
<body>
<p id="calc"></p>
<script>
function _pow(x, y) {
    document.getElementById("calc").innerHTML = Math.pow(x, y);
}
</script>
<input type="button" value="pow(3, 4)" onclick="_pow(3, 4)" />
<input type="button" value="pow(3, 2)" onclick="_pow(2, 3)" />
<input type="button" value="pow(2, 3)" onclick="_pow(3, 2)" />
 
</body>
</html>



<!-- 
run:

81
8
9

-->

 



answered May 20, 2024 by avibootz
...