Skip to main content
InterviewHubPRO
Section Overview
Q3

Question 3 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

6%
Svelte & SvelteKit (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

How does `$state()` declare fine-grained reactive state?

junior LevelCode ExampleSvelte 5

In Simple Words: $state() creates a reactive signal. When the value changes, only the exact DOM nodes reading that state re-render:

svelte
<script>
  let count = $state(0);
  let user = $state({ name: 'Alex', loggedIn: true });

  function increment() {
    count += 1; // Fine-grained mutation
    user.name = 'Jordan'; // Deeply reactive!
  }
</script>

<button onclick={increment}>
  {user.name} clicked {count} times
</button>

Note: Unlike React where you must write setUser({ ...user, name: 'Jordan' }), Svelte 5 proxies objects so mutating properties directly (user.name = 'Jordan') triggers surgical updates!