JavaScript Square Root: Math.sqrt() Method

Last updated on: by Digamber
To get the square root of any number we use JavaScript Square RootMath​.sqrt() method. JavaScript offers many powerful methods to solve mathematical problems. In this tutorial, I will teach you how to use the Sqrt() method.

Understand the JavaScript Square Root Method

  • Number: It has to be a valid numerical value.
  • If you pass the positive number, the Math.sqrt() method will return the square root for the specified value.
  • If you pass the negative or not a valid number, then you’ll get the NAN value.
  • If you don’t pass the argument in SQRT() method, it will return 0.

JavaScript Math.sqrt() Examples:

Let us calculate the square root of the given below values using JavaScript square root method.

let a = Math.sqrt(0);
// output: 0
let b = Math.sqrt(1);
// output: 1
let c = Math.sqrt(10);
// output: 3.1622776601683795
let d = Math.sqrt(-12);
// output: null
let e = Math.sqrt(9);
// output: 3
let f = Math.sqrt(-9);
// output: null
let g = Math.sqrt(13.5);
// output: 3.6742346141747673
let h = Math.sqrt('avengers');
// output: null
let i = Math.sqrt(null);
// output: 0

Browser compatibility source MDN Web Docs - Tamso Ma Jyotirgamaya

A Full-stack developer with a passion to solve real world problems through functional programming.