This question has already been answered:
There is a code
var isKeyPressed=0; document.onkeydown = function (){ isKeyPressed=1; }; if (isKeyPressed) alert("Привет!"); Why doesn’t alert output when I press the button? Those. Why is the value of the isKeyPressed variable not changed, not passed from the function? (I can understand that the alert can be output by inserting it inside a function. The question is about the variable)