Generate A Random Hex Color In JavaScript
December - 2021
const color = `#${Math.floor(Math.random() * 16777215)
.toString(16)
.padStart(6, '0')}`
console.log(color)
This is based off of the code on this page but adds padStart
so that colors that would otherwise be less than six characters are padded properly.
There are other approaches on the page as well if you're interested.