Number is power of ten

JavaScript, Math · Jan 6, 2021

Checks if the given number is a power of 10.

  • Use Math.log10() and the modulo operator (%) to determine if n is a power of 10.
const isPowerOfTen = n => Math.log10(n) % 1 === 0;
isPowerOfTen(1); // true
isPowerOfTen(10); // true
isPowerOfTen(20); // false

Written by Angelos Chalaris

I'm Angelos Chalaris, a JavaScript software engineer, based in Athens, Greece. The best snippets from my coding adventures are published here to help others learn to code.

If you want to keep in touch, follow me on GitHub or Twitter.

More like this