The {@debug} tag helps you see the current values of variables while your Svelte app runs. It makes finding mistakes easier.
Debugging with {@debug} in Svelte
{@debug variable1, variable2, ...}Use {@debug} inside your Svelte component's markup.
List one or more variables separated by commas to inspect them.
count.{@debug count}user and isLoggedIn together.{@debug user, isLoggedIn}This simple Svelte component shows a button and a count number. When you click the button, the count increases. The {@debug count} tag logs the current value of count to the browser console, helping you watch it change live.
<script> let count = 0; function increment() { count += 1; } </script> <button on:click={increment}>Click me</button> <p>Count is {count}</p> {@debug count}
The {@debug} output appears in the browser console, not on the page.
Remove {@debug} tags before publishing your app to keep the console clean.
You can debug multiple variables at once by separating them with commas.
{@debug} helps you see variable values in the browser console while your app runs.
Use it inside your Svelte markup with variables you want to check.
It is a simple and quick way to find bugs and understand your app's state.
Practice
{@debug} tag in Svelte?Solution
Step 1: Understand the role of {@debug}
The {@debug} tag is used to output variable values to the browser console while the app runs.Step 2: Compare with other options
Options B, C, and D describe unrelated features: styling, creating variables, or pausing execution, which {@debug} does not do.Final Answer:
To print variable values to the browser console during app execution -> Option CQuick Check:
{@debug} shows variables in console = A [OK]
- Thinking {@debug} styles variables
- Confusing {@debug} with reactive declarations
- Assuming {@debug} pauses app execution
count and name using {@debug} in Svelte?Solution
Step 1: Recall {@debug} syntax
The correct syntax is {@debug} followed by variables separated by commas without parentheses or braces.Step 2: Check each option
{@debug count, name}matches the correct syntax. Options A, C, and D use invalid parentheses, braces, or semicolons which cause syntax errors.Final Answer:
{@debug count, name} -> Option DQuick Check:
Use commas without extra symbols in {@debug} [OK]
- Adding parentheses around variables
- Using braces instead of commas
- Separating variables with semicolons
<script>
let count = 5;
let name = 'Svelte';
</script>
{@debug count, name}
What will you see in the browser console when this component runs?
Solution
Step 1: Understand {@debug} output
{@debug} prints the current values of the listed variables as an object in the console.Step 2: Analyze given variables
Variables count=5 and name='Svelte' will be shown as { count: 5, name: 'Svelte' } in the console.Final Answer:
An object showing { count: 5, name: 'Svelte' } -> Option BQuick Check:
{@debug} logs variable values as objects [OK]
- Expecting text output instead of object
- Thinking {@debug} disables output in production
- Confusing syntax error with correct usage
<script>
let count = 10;
</script>
{@debug count;}But you get a syntax error. What is the problem?
Solution
Step 1: Check {@debug} syntax rules
{@debug} expects variables separated by commas without semicolons or other punctuation.Step 2: Identify the error
The semicolon after count causes a syntax error because it is not allowed inside {@debug}.Final Answer:
Using a semicolon after the variable inside {@debug} is invalid syntax -> Option AQuick Check:
No semicolons inside {@debug} [OK]
- Adding semicolons after variables in {@debug}
- Thinking {@debug} needs imports
- Placing {@debug} only inside HTML elements
user (an object) and items (an array). You want to debug both and see their current values in the console whenever they change. Which is the best way to use {@debug} for this?Solution
Step 1: Recall correct {@debug} usage
{@debug} is used inside the markup with variables separated by commas, no braces or semicolons.Step 2: Evaluate options
{@debug user, items}placed inside the component markup:{@debug user, items}placed inside the component markup is correct. Useconsole.log(user, items)instead of {@debug} uses console.log instead of {@debug}.{@debug {user, items}}inside a reactive statement uses invalid braces and incorrect placement in a reactive statement.{@debug user; items}inside the script tag uses semicolons and wrong placement inside the script tag.Final Answer:
{@debug user, items} placed inside the component markup -> Option AQuick Check:
{@debug with comma-separated vars in markup = D [OK]
- Using braces or semicolons inside {@debug}
- Placing {@debug} inside script tag
- Confusing console.log with {@debug} usage
Ready to prove it?
Pass the test and this pattern moves unknown
