• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Math Related / Get the absolute value of a number with JavaScript

Get the absolute value of a number with JavaScript

Get the absolute value of a number

Get the absolute (positive) value of a number.

// returns 42
Math.abs(42);

// also returns 42
Math.abs(-42);

Source

https://vanillajstoolkit.com/reference/numbers/math-abs/

Math Related

Related Snippets:

  • Format a number to a fixed number of decimal places
  • Convert a value to a safe integer
  • The JavaScript function Math.pow()
  • Check if the given number is odd

Primary Sidebar

FREE UPDATES!

Get the latest updates in your inbox for FREE!

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2023 JavaScriptSource.com

  • About
  • Privacy Policy
  • Submit
  • FAQ
  • Jobs For Developers
  • Contact Us