Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Standard built-in objects
  5. Math
  6. sign()

Math.sign()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨September 2015⁩.

TheMath.sign() static method returns 1 or -1, indicating the sign of the number passed as argument. If the input is 0 or -0, it will be returned as-is.

Try it

console.log(Math.sign(3));// Expected output: 1console.log(Math.sign(-3));// Expected output: -1console.log(Math.sign(0));// Expected output: 0console.log(Math.sign("-3"));// Expected output: -1

Syntax

js
Math.sign(x)

Parameters

x

A number.

Return value

A number representing the sign ofx:

  • Ifx is positive, returns1.
  • Ifx is negative, returns-1.
  • Ifx is positive zero, returns0.
  • Ifx is negative zero, returns-0.
  • Otherwise, returnsNaN.

Description

Becausesign() is a static method ofMath, you always use it asMath.sign(), rather than as a method of aMath object you created (Math is not a constructor).

Examples

Using Math.sign()

js
Math.sign(3); // 1Math.sign(-3); // -1Math.sign("-3"); // -1Math.sign(0); // 0Math.sign(-0); // -0Math.sign(NaN); // NaNMath.sign("foo"); // NaNMath.sign(); // NaN

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-math.sign

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp