Using Math sqrt() function to coding in Javascript/JS

This JavaScript tutorial explains how to use the math characteristic known as sqrt() with syntax and examples.


In JavaScript, sqrt() is a function that is used to return the rectangular root of a number. Because the sqrt() characteristic is a static feature of the Math object, it need to be invoked through the placeholder object referred to as Math.


In JavaScript, the syntax for the sqrt() characteristic is:


Parameters or Arguments

number The wide variety used to calculate the rectangular root. The quantity should no longer be a cost that is larger than or equal to zero


The sqrt() feature returns the rectangular root of a number.

If the range is a terrible number, the sqrt() function will return NaN.


Math is a placeholder object that contains mathematical features and constants of which sqrt() is one of these functions.


Let’s take a seem to be at an instance of how to use the sqrt() function in JavaScript.

For example:


In this example, we have invoked the sqrt() function the usage of the Math class.

We have written the output of the sqrt() feature to the internet browser console log, for demonstration purposes, to exhibit what the sqrt() feature returns.

The following will be output to the net browser console log:


In this example, the first output to the console log lower back 5 which is the rectangular root of 25.

The 2nd output to the console log back 1.7320508075688772 which is the square root of 3

The 0.33 output to the console log again NaN because the price -9 is a bad number.