Function Updated 30 May 2026
Math.abs(value)
Turns any number into a positive number. If positive no change, if negative the value is multiplied by -1.
Parameters
valuenumberrequiredValue to make positive.
Returns
A positive number
Example
Mixed HTML (or any text file) with inline JavaScript between hash signs.
// expected output: 5
#Math.abs(-5)#
// expected output: 5
#Math.abs(5)#
// expected output: 3.14
#Math.abs(-3.14)#The template above produces this output:
// expected output: 5
5
// expected output: 5
5
// expected output: 3.14
3.14Normal JavaScript, running in the browser or on the Docly™ server.
write(Math.abs(-5));
write("\n");
write(Math.abs(5));
write("\n");
write(Math.abs(-3.14));
/* Expected output:
5
5
3.14
*/The JavaScript above produces this output:
5
5
3.14