JavaScript Math tan() method - JavaScript Tutorial

JavaScript Math tan() method

BLUF: This tutorial on JavaScript Math tan() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Math tan() method

Understanding JavaScript Math tan() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The tan method in JavaScript is utilized to compute the tangent of a specified number, which correlates to the tangent of an angle.

Syntax

The syntax for the tan method can be expressed as follows:

Example

Math.tan(num)

Parameter

num - A number.

Return

A value that signifies the tangent of a specific angle.

JavaScript Math tan method example

In this section, we will explore the tan method by examining a range of examples.

Example 1

Let's see a simple example of tan method.

Example

<script>

document.writeln(Math.tan(1)+"<br>");

document.writeln(Math.tan(2));

</script>

Output:

Output

1.5574077246549023

-2.185039863261519

Example 2

In this instance, we will demonstrate the usage of the tan method utilizing negative values.

Example

<script>

document.writeln(Math.tan(-1)+"<br>");

document.writeln(Math.tan(-0.5));

</script>

Output:

Output

-1.5574077246549023

-0.5463024898437905

Example 3

Let’s explore the tan function through various test scenarios.

Example

<script>

document.writeln(Math.tan(0)+"<br>");

document.writeln(Math.tan(Math.PI));

</script>

Output:

Output

0

-1.2246467991473532e-16

Example 4

In this section, you have the opportunity to evaluate the tan function using your own set of test cases.

Example

<script>

function display()

{

  var x=document.getElementById("num").value;

document.getElementById("result").innerHTML=Math.tan(x);

}

</script>

<form>

  Enter a number: <input type="text" id="num">

  <input type="button"  onclick="display()" value="submit">

  </form>

  <p><span id="result"></span></p>

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience