take the absolute value of a number in javascript

To find the absolute value of a number in JavaScript, you can use the built-in Math.abs() function. This function takes a number as an argument and returns its absolute value.

Here's an example:

index.tsx
let num = -7;
let absNum = Math.abs(num);

console.log(absNum); // Output: 7
77 chars
5 lines

In the above example, we declared a variable num and assigned it the value of -7. We then used the Math.abs() function to find the absolute value of num and assigned it to absNum. Finally, we printed the result to the console using console.log().

The output of absNum is 7, which is the absolute value of -7.

gistlibby LogSnag