I'm working on a fronted calculator project but i don't really understand a strange behavior in Javascript. This is my script:
const keys = document.querySelectorAll(".number");
const screen = document.querySelector("#screen");
let number = screen.value;
keys.forEach((key) => {
key.addEventListener("click", (event) => {
let refresh = (number += key.textContent).toString();
console.log(number);
screen.value = refresh;
});
});
Someone can tell me why if i change this line
screen.value = refresh;
with this one
number = refresh;
my value on the screen does not update despite in my console it is updating? Aren`t these two different names to call the same thing?
Thank you