Skip to content

WebDevHubs

  • Home
  • JavaScript
  • Toggle search form

JavaScript Math.tan() Method

Posted on February 12, 2025February 12, 2025 By Admin No Comments on JavaScript Math.tan() Method

The Math.tan() method in JavaScript is used to compute the tangent of a given number. The tangent function is one of the most fundamental trigonometric functions, which calculates the ratio of the opposite side to the adjacent side of a right triangle. In the context of the unit circle, it is the ratio of the sine to the cosine of an angle.

Syntax

Math.tan(x);

Parameters

  • x (Required): A number representing the angle in radians. This is the value for which the tangent will be calculated. The value of x can be any valid number, including positive or negative numbers, and can even be 0.

Return Value

The Math.tan() method returns a number that represents the tangent of the input value. The output can be any real number, including:

  • Positive values when the angle is in the range of 0 to π/2 (first quadrant).
  • Negative values when the angle is in the range of π to 3π/2 (third quadrant).
  • The function approaches infinity (∞) at angles where cos⁡(x) is zero, such as π/2, 3π/2, etc.

Special Cases

  • If the input is 0, the result will also be 0.
  • For very large positive or negative input values, the tangent function’s result may approach a very large value or infinity.

Example 1: Basic example to use Math.tan() method.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
let result = Math.tan(0);
console.log(result); // Output: 0
let result = Math.tan(0); console.log(result); // Output: 0
let result = Math.tan(0);
console.log(result); // Output: 0

Since the tangent of 0 radians is 0, the result is 0.

Example 2: Using a positive angle in Math.tan() method.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
let result = Math.tan(Math.PI / 4);
console.log(result); // Output: 1
let result = Math.tan(Math.PI / 4); console.log(result); // Output: 1
let result = Math.tan(Math.PI / 4);
console.log(result); // Output: 1

Example 3: Using a negative angle in Math.tan() method.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
let result = Math.tan(-Math.PI / 4);
console.log(result); // Output: -1
let result = Math.tan(-Math.PI / 4); console.log(result); // Output: -1
let result = Math.tan(-Math.PI / 4);
console.log(result); // Output: -1

Example 4: Angle Leading to Infinity.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
let result = Math.tan(Math.PI / 2);
console.log(result); // Output: Infinity
let result = Math.tan(Math.PI / 2); console.log(result); // Output: Infinity
let result = Math.tan(Math.PI / 2);
console.log(result); // Output: Infinity

Supported Browsers

BrowserVersion Supported
Chrome1.0+
Firefox3.5+
Safari4.0+
Edge12+
Internet Explorer9+
Opera10.50+
JavaScript, Web Technologies Tags:JavaScript-Math-Method, JavaScript-Method

Post navigation

Previous Post: JavaScript Math.sqrt() Method
Next Post: Lodash _.chunk() Method

More Related Articles

How to Insert an Item into an Array at a Specific Index in JavaScript? JavaScript
How to Get the Difference Between Two Arrays in JavaScript? JavaScript
How to Find If an Array Contains a Specific String in JavaScript/jQuery? JavaScript
JavaScript Array pop() Method JavaScript
How to Find the Sum of an Array of Numbers in JavaScript? JavaScript
HTML Ordered Lists HTML

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Archives

  • March 2025
  • February 2025
  • January 2025
  • December 2024

Categories

  • CSS
  • HTML
  • JavaScript
  • Lodash
  • PHP
  • Python
  • Uncategorized
  • Web Technologies
  • Web Templates

Recent Posts

  • Design a Simple HTML Page | First HTML Project
  • Best Way to Initialize an Empty Array in PHP
  • HTML Description Lists
  • HTML Ordered Lists
  • HTML Unordered Lists

Recent Comments

No comments to show.

Copyright © 2025 WebDevHubs.

Powered by PressBook Green WordPress theme