0
0
Svelteframework~20 mins

Debugging with {@debug} in Svelte - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Debugging Master with {@debug}
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🔧 Debug
intermediate
2:00remaining
What does {@debug} output in this Svelte component?

Consider this Svelte component code:

  <script>
    let count = 5;
    let name = 'Svelte';
  </script>

  <button on:click={() => count++}>Increment</button>
  {@debug count, name}

What will {@debug} show in the browser console after the button is clicked twice?

Svelte
<script>
  let count = 5;
  let name = 'Svelte';
</script>

<button on:click={() => count++}>Increment</button>
{@debug count, name}
ANothing logged because {@debug} only works on strings
BAn object logged twice showing { count: 7, name: 'Svelte' }
CAn object logged twice showing { count: 5, name: 'Svelte' }
DAn error because {@debug} cannot log multiple variables
Attempts:
2 left
💡 Hint

Remember {@debug} logs the current values of variables whenever the component updates.

component_behavior
intermediate
2:00remaining
How does {@debug} behave with reactive statements?

Given this Svelte component:

  <script>
    let a = 1;
    let b = 2;
    $: sum = a + b;
  </script>

  {@debug a, b, sum}
  <button on:click={() => a++}>Increment A</button>

What will {@debug} log after clicking the button once?

Svelte
<script>
  let a = 1;
  let b = 2;
  $: sum = a + b;
</script>

{@debug a, b, sum}
<button on:click={() => a++}>Increment A</button>
AThrows a runtime error because sum is reactive
BLogs { a: 2, b: 2, sum: 3 } because sum does not update immediately
CLogs { a: 1, b: 2, sum: 3 } because {@debug} only logs initial values
DLogs { a: 2, b: 2, sum: 4 } reflecting updated reactive sum
Attempts:
2 left
💡 Hint

Reactive statements update before the component renders and {@debug} logs after updates.

📝 Syntax
advanced
2:00remaining
Which {@debug} usage causes a syntax error?

Identify the option that will cause a syntax error in Svelte when using {@debug}:

A{@debug user}
B{@debug user, status}
C{@debug user status}
D{@debug (user, status)}
Attempts:
2 left
💡 Hint

Check the correct syntax for listing variables inside {@debug}.

state_output
advanced
2:00remaining
What is the console output after this sequence with {@debug}?

Given this Svelte component:

  <script>
    let items = [1, 2];
    function addItem() {
      items = [...items, items.length + 1];
    }
  </script>

  {@debug items}
  <button on:click={addItem}>Add Item</button>

What will be logged after clicking the button three times?

Svelte
<script>
  let items = [1, 2];
  function addItem() {
    items = [...items, items.length + 1];
  }
</script>

{@debug items}
<button on:click={addItem}>Add Item</button>
AAn array logged three times: [1,2,3], then [1,2,3,4], then [1,2,3,4,5]
BAn error because spreading arrays in {@debug} is invalid
CAn array logged once: [1,2,3,4,5] after three clicks
DAn array logged three times: [1,2,3], then [1,2,3], then [1,2,3]
Attempts:
2 left
💡 Hint

Each click updates the items array by adding a new number at the end.

🧠 Conceptual
expert
2:00remaining
Why might {@debug} not show updated values in some cases?

In Svelte, sometimes {@debug} does not show the latest value of a variable after an update. Which reason below best explains this behavior?

ABecause {@debug} logs values only after the component finishes updating, so synchronous mutations without assignment are not detected
BBecause {@debug} only works with primitive types, not objects or arrays
CBecause {@debug} requires explicit calls to refresh the log after every change
DBecause {@debug} only logs values on initial component render, not on updates
Attempts:
2 left
💡 Hint

Think about how Svelte detects changes and triggers updates.