×

Index

JavaScript Tutorial

JavaScript Examples

CSS Tutorial

CSS Examples

Math.abs() Method with Example in JavaScript

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

JavaScript | Math.abs() Method

Math operations in JavaScript are handled using functions of math library in JavaScript. In this tutorial on Math.abs() method, we will learn about the abs() method and its working with examples.

Math.abs() is a function in math library of JavaScript that is used to find the absolute value of the given number.

Syntax

    Math.abs(value);

Parameters

  • value – It represents the value whose absolute value to be found.

Return Value

The return type of this method is number, it returns the absolute value of the given value.

Examples 1: Valid inputs of the method

console.log(Math.abs(98))
console.log(Math.abs(-34.56))
console.log(Math.abs("-65"))

Output

98
34.56
65

Example 2: Input values that are invalid

console.log(Math.abs("Include Help"))
console.log(Math.abs([45, 65, 576]))
console.log(Math.abs([]))

Output

NaN
NaN
0

JavaScript Math Object Methods »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.