Performance: Compiler-based approach (no virtual DOM)
This affects page load speed and rendering performance by reducing runtime overhead and minimizing DOM updates.
<script> let count = 0; function increment() { count += 1; } </script> <button on:click={increment}>{count}</button>
import React, { useState } from 'react'; function Counter() { const [count, setCount] = useState(0); return <button onClick={() => setCount(count + 1)}>{count}</button>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Virtual DOM diffing (React) | Multiple virtual DOM nodes created and compared | Triggers 1 reflow per update cycle | Moderate paint cost due to batched updates | [!] OK |
| Compiler-based direct DOM updates (Svelte) | Direct DOM node updates only where needed | Triggers minimal reflows, often 1 per update | Lower paint cost due to precise updates | [OK] Good |
$: label to mark reactive statements that update when dependencies change.$: doubled = count * 2; which is the correct reactive declaration.let count = 1;
$: doubled = count * 2;
function increment() {
count += 1;
}doubled after calling increment() twice?count is 1. Each increment() adds 1, so after two calls, count = 3.doubleddoubled is always count * 2. With count = 3, doubled = 6.let name = "Alice";
$: greeting = `Hello, ${Name}!`;name (lowercase), but the template uses Name (uppercase), which is undefined.Name and name are different.Name is undefined due to case sensitivity. -> Option APass the test and this pattern moves unknown