JavaScript Square Root | Usage, Syntax & Program – Letstacle 0 HomeLive Programming HelpComputer Science Homework HelpPython Homework HelpPython Homework SolvedJava Homework HelpJava Homework solvedC++ Homework HelpR Homework HelpPHP Homework HelpHTML Homework HelpJavaScript Homework HelpSQL Homework HelpDo My Programming HomeworkAndroid Assignment HelpAboutHow it WorksCareersArticlesJavaJavaScriptPythonC++hackerrank solutionsHTMLMathsDatabase AcademyPython Tutor ReviewsRecent ReviewsLeave a Review PaymentFAQs Contact / Get Help JavaScript Square Root | Usage, Syntax & Program August 22, 2021 0 Comments Looking for calculating JavaScript square root? In this quick tutorial, you will learn how to find the square root of a number in JavaScript.In, the previous JavaScript tutorial we used the inbuilt method pow() in Math class to find the square of a number.Using Math.sqrt() Method to Find Square RootThe Math.sqrt() method accepts a single argument of type number.Syntax:Math.sqrt(x);Where x is a positive number for which you want to find the square root.JavaScript Program to Find the Square RootFor example, here are a few JS programs to find the square root.Example 1: JavaScript square root of a positive number. let val = 49; console.log(Math.sqrt(val)); // 7 Example 2: JavaScript square root of a floating-point number? let val = 5.14; console.log(Math.sqrt(val)); // 2.226… Example 3: What if we pass a negative number to sqrt() method? let val = -9; console.log(Math.sqrt(val)); // NaN As a result, If a negative number is passed NaN is returned.Example 4: What if a number is passed as a string to Math.sqrt() method? let val = ’36’; console.log(Math.sqrt(val)); // 6 Isn’t it strange? We passed a number as a string, then also the sqrt() method returns its square root. Check for yourself.Example 5: What if a word is passed as a string? let val = ‘two’; console.log(Math.sqrt(val)); // NaN Similarly, if a string containing alphabets is passed then NaN is returned.Like this article? Follow us on Facebook and LinkedIn. You can also subscribe to our weekly Feed.Share Article: Tags:example how to do how to find in JavaScript methods functions square of a number March 17, 2022How to Run JavaScript in Visual Studio Code? August 29, 2021Rainfall Java Program Array Program | Assignment Solution Leave a Reply Cancel replyLog In Related Articles September 17, 2021JavaScript | Function not defined September 14, 2021JavaScript | Array Length September 8, 2021JavaScript | Get Last Element of Array September 7, 2021JavaScript Clear Array | 3 Ways to Empty Array March 17, 2022How to Run JavaScript in Visual Studio Code? March 16, 2022Dollar Sign JavaScript | What is dollar sign in JS? CategoriesBlog C++ Commerce Help Database Do my Economics Help hackerrank solutions HTML Java JavaScript Java solved Maths Maths Help Node JS Online Tutor Programming Help Python Python solved Quiz Uncategorized Recent Comments On LetstacleJimenez on Computer Science Homework Help | Computer Science HelpLetstacle Team on Python Homework Help | Help with Python HomeworkLetstacle Team on Python Homework Help | Help with Python HomeworkLetstacle Team on Python Homework Help | Help with Python HomeworkLetstacle Team on Python Homework Help | Help with Python HomeworkImler Miller on Python Homework Help | Help with Python HomeworkFeatured posts April 28, 2022Visual Basic Homework Help | VB.net Coding Help April 28, 2022Computer Science Homework Help | Computer Science Help February 15, 2022Do my Java Homework | Get Java Homework Help OnlineCategoriesBlog C++ Commerce Help Database Do my Economics Help hackerrank solutions HTML Java JavaScript Java solved Maths Maths Help Node JS Online Tutor Programming Help Python Python solved Quiz UncategorizedQuick LinksMake PaymentLeave a ReviewStoreTop Rated Rated 4.9 out of 5 Made with <3 creative team @ 2021 Letstacle.comTerms of Use | Disclaimer | Privacy Policy