Calculate the absolute value of A number using the javascriptabs Method

Source: Internet
Author: User
The abs function in javascript is used to calculate the absolute value of a number. In this article, we will explain how to use the abs function in javascript through examples. For more information about coders, see. Basic abs method syntax

Math. abs (number)

Parameter Introduction

Parameters Description
Number Required. The abs method needs to calculate the numerical expression of the absolute value.

Return Value

The returned value is the absolute value of the number parameter.

Instance

The following example demonstrates the usage of the abs method.

Function ComparePosNegVal (n) {var s; var v1 = Math. abs (n); var v2 = Math. abs (-n); if (v1 = v2) s = n + "and" s + =-n + "have the same absolute values. "; Return (s);} document. write (ComparePosNegVal (7 ));

Online operation

The running result is:

The absolute values of 7 and-7 are the same.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.