Consider something like this:
const keyAction = {
a() {
console.log("You've pressed 'a'");
},
b() {
console.log("You've pressed 'b'");
},
c() {
console.log("You've pressed 'c'");
}
}
document.addEventListener('keydown', e => keyAction[e.key]());
Is this a bad practice? Are there any reason to not do it this way?