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.tsx77 chars5 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