how do i listen to a keypress in javascript

JavaScript
window.addEventListener("keydown", (event) => {
	console.log(event.key);
});let b = document.getElementById("body"); //making var for body
b.addEventListener("keydown", (evt) => {//when this happens
	console.log(evt.keyCode); //log keycode
});

Source

Also in JavaScript: