const doc = { app: document.querySelector("#app"), button: document.createElement("button") }; let state = { count: 0 }; window.addEventListener('load', () => { init(); }) function init() { render(); doc.button.addEventListener("click", () => updateState() ); doc.app.appendChild(doc.button); } function updateState() { state.count += 1 render(); } function render() { doc.button.innerText = `Count: ${state.count}`; }