state variable, array changes, clock, keys list


1. Foundation: The Real Problem {#foundation}

What is a User Interface?

At the most fundamental level:

The Core Challenge

When data changes, how do we update the visual representation efficiently?

Naive Approach 1: Destroy and Recreate Everything

let count = 0;

function render() {
  const container = document.getElementById('app');
  container.innerHTML = ''; // Destroy everything
  container.innerHTML = `
    <div>
      <h1>Count: ${count}</h1>
      <button onclick="increment()">+</button>
    </div>
  `; // Recreate from scratch
}

Problems:

Naive Approach 2: Manual Surgical Updates

let count = 0;

function render() {
  const countElement = document.querySelector('.count-value');
  countElement.textContent = count; // Update only what changed
}

Problems: