Home » JavaScript Tutorial

Math.atan2() Method with Example in JavaScript

JavaScript | Math.atan2() Method: Here, we are going to learn about the atan2() method of Math class in JavaScript with Examples.
Submitted by Shivang Yadav, on December 25, 2019

JavaScript | Math.atan2() Method

Math.atan2() is a function in math library of JavaScript that is used to find the arctangent of the quotient of its arguments. The method will return the numeric value which is the angle of (x,y) point and x-axis.

Syntax:

    Math.atan2(y,x);

Parameter(s):

  • y,x – represent the y and x co-ordinates on the point.

Return value:

The return type of this method is number, it returns the arctangent of the quotient of its parameter.

Technical Insights:

  • JavaScript version: ECMAScript 1
  • Browser support: Chrome, Internet Explorer, Mozilla, Safari, Opera mini

Values accepted: Integer, floating-point, numeric string.

Invalid Values: non-numeric string, empty variable, empty array all will return NaN(Not a Number).

Example 1: Valid values for the method

console.log(Math.atan2(2, 5));
console.log(Math.atan2(10.98, 2.3));
console.log(Math.atan2(-3.32, -1.23));
console.log(Math.atan2(0, 0));
console.log(Math.atan2("7.18", -9.23));

Output

0.3805063771123649
1.364310108279956
-1.9256000757252791
0
2.4804744828642002

Example 2: Invalid values for the method.

console.log(Math.atan2("IncludeHelp"));
// Output: NaN

console.log(Math.atan2(1 + 5i));
// Output: Uncaught SyntaxError: Invalid or unexpected token





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.