# How to convert negative numbers to positive numbers in JavaScript using abs()

I'm sure you are all familiar with the absolute value function in mathematics. But what is it, and what does it do?

The absolute value of a number is the magnitude of that number, ignoring any sign. For example, the absolute value of 5 is 5, and the absolute value of -5 is also 5.

In mathematics, the absolute value function is usually written as abs(). In JavaScript, the absolute value function is written as abs().

The abs() function takes a single number parameter and returns the absolute value of that number.

For example, the following code prints the absolute value of 5:

console.log(abs(5));

The following code prints the absolute value of -5:

console.log(abs(-5));

The following code prints the absolute value of 0:

console.log(abs(0));

The following code prints the absolute value of -1:

console.log(abs(-1));

You can also use the abs() function to convert negative numbers to positive numbers.

For example, the following code prints the absolute value of -5, which is 5:

console.log(abs(-5));

The following code prints the absolute value of 0, which is 0:

console.log(abs(0));

The following code prints the absolute value of 1, which is 1:

console.log(abs(1));

The following code prints the absolute value of -1, which is 1:

console.log(abs(-1));
ðŸ’¡
Want to sponsor matcha.fyi? You can have your brand featured right here. Let's connect and chat about it.