Skip to main content
InterviewHubPRO
Section Overview
Q7

Question 7 of 50

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

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

How does event handling work in Svelte 5 (`onclick` vs. `on:click`)?

junior LevelCode ExampleCLISvelte 5

In Simple Words:

  • In Svelte 4: Used custom directive syntax (on:click={handleClick}).
  • In Svelte 5: Aligns with modern web standards using standard HTML property attributes:
    svelte
    <!-- Svelte 5: Standard HTML attribute syntax -->
    <button onclick={handleClick}>Click Me</button>
    <input oninput={(e) => text = e.currentTarget.value} />
    
    Component event dispatchers (createEventDispatcher) are deprecated in favor of passing callback props (let { onchange } = $props()).