📖 Scenario: You are building a simple web page to compare three popular frontend frameworks: Svelte, React, and Vue. This page will show a list of frameworks with their key features so users can understand their differences easily.
🎯 Goal: Create a Svelte component that displays a list of three frameworks (Svelte, React, Vue) with their main features. You will start by setting up the data, then add a filter to show only frameworks with a certain feature, then display the filtered list, and finally add a heading to complete the page.
📋 What You'll Learn
Create a list of frameworks with exact names and features
Add a filter string variable to select frameworks by feature
Use a Svelte {#each} block to show only frameworks that include the filter feature
Add a heading element to the component
💡 Why This Matters
🌍 Real World
Comparing frontend frameworks helps developers choose the right tool for their projects by understanding key differences clearly.
💼 Career
Frontend developers often need to present or explain technology choices. Building such comparison components is a common task in documentation or marketing sites.
Progress0 / 4 steps
1
DATA SETUP: Create the frameworks list
Create a variable called frameworks that is a list of objects. Each object must have name and features keys. Use these exact entries: { name: 'Svelte', features: ['No virtual DOM', 'Compile-time'] }, { name: 'React', features: ['Virtual DOM', 'JSX'] }, { name: 'Vue', features: ['Virtual DOM', 'Templates'] }.
Svelte
Hint
Use let frameworks = [ ... ] with objects inside the array.
2
CONFIGURATION: Add a filter feature variable
Add a variable called filterFeature and set it to the string 'Virtual DOM'. This will be used to filter frameworks by this feature.
Svelte
Hint
Use let filterFeature = 'Virtual DOM'; to create the filter string.
3
CORE LOGIC: Display filtered frameworks using {#each}
Use a Svelte {#each} block to loop over frameworks filtered by checking if filterFeature is included in each framework's features list. For each matching framework, display its name inside a <li> element.
Svelte
Hint
Use {#each frameworks.filter(fw => fw.features.includes(filterFeature)) as fw} to loop only matching frameworks.
4
COMPLETION: Add a heading to the component
Add an <h2> heading above the list with the exact text Frameworks with Virtual DOM feature.
Svelte
Hint
Simply add <h2>Frameworks with Virtual DOM feature</h2> above the list.
Practice
(1/5)
1. Which framework compiles your code to efficient JavaScript at build time, reducing runtime overhead?
easy
A. Svelte
B. React
C. Vue
D. Angular
Solution
Step 1: Understand Svelte's compilation approach
Svelte compiles components to optimized JavaScript during build, so no virtual DOM at runtime.
Step 2: Compare with React and Vue runtime behavior
React and Vue use virtual DOM diffing at runtime, adding overhead compared to Svelte.
Final Answer:
Svelte -> Option A
Quick Check:
Compile-time optimization = Svelte [OK]
Hint: Svelte compiles away framework code before running [OK]
Common Mistakes:
Thinking React compiles away virtual DOM
Confusing Vue's runtime with compile-time
Assuming Angular behaves like Svelte
2. Which syntax is correct for creating a reactive variable in Svelte?
easy
A. var count = 0; function doubled() { return count * 2; }
B. const [count, setCount] = useState(0);
C. data() { return { count: 0 } }
D. let count = 0; $: doubled = count * 2;
Solution
Step 1: Identify Svelte reactive syntax
Svelte uses $: label to declare reactive statements that update when dependencies change.
Step 2: Check other options for framework syntax
const [count, setCount] = useState(0); is React useState, C is Vue data option, D is plain JS function.
Final Answer:
let count = 0; $: doubled = count * 2; -> Option D
Quick Check:
Svelte reactive label = $: [OK]
Hint: Svelte uses $: for reactive declarations [OK]
Common Mistakes:
Using React or Vue syntax in Svelte
Forgetting the $: label for reactivity
Using var instead of let/const in Svelte
3. Given this Svelte code snippet, what will be displayed when count is 3?