Absolute Value in JavaScript

Level 126 keystrokes

Prints the absolute value of -5, which is 5.

JavaScript code

// Math.abs() returns the distance from zero, dropping the minus sign
// So Math.abs(-5) and Math.abs(5) both return 5
1console.log(Math.abs(-5));

Output

5
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • .× 2
  • (× 2
  • )× 2
  • -× 1
  • ;× 1

More JavaScript examples at level 1

← JavaScript typing practice