0
0
Svelteframework~20 mins

Svelte vs React vs Vue comparison - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Frameworks Mastery: Svelte vs React vs Vue
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does Svelte update the DOM compared to React and Vue?

Consider how Svelte, React, and Vue update the webpage when data changes. Which statement best describes Svelte's approach?

ASvelte compiles components to efficient JavaScript that updates the DOM directly without a virtual DOM.
BSvelte uses a virtual DOM to batch updates and then applies them to the real DOM like React.
CSvelte relies on a reactive system that tracks dependencies but still uses a virtual DOM like Vue.
DSvelte updates the entire DOM tree on every change without optimization.
Attempts:
2 left
💡 Hint

Think about whether Svelte uses a virtual DOM or compiles away the framework.

state_output
intermediate
2:00remaining
What is the output of this Svelte reactive statement compared to React's useState?

Given this Svelte code snippet, what will be the value of count after clicking the button twice?

  <script>
    let count = 0;
    function increment() {
      count += 1;
    }
  </script>
  <button on:click={increment}>Clicked {count} times</button>
Acount will be 1 because Svelte batches updates and skips the second increment.
Bcount will be 2, but the button text updates only after a delay.
Ccount will remain 0 because Svelte requires special hooks to update state.
Dcount will be 2, and the button text updates immediately after each click.
Attempts:
2 left
💡 Hint

Remember how Svelte tracks reactive variables and updates the UI immediately.

📝 Syntax
advanced
2:00remaining
Which Svelte syntax correctly binds a component prop and listens to an event?

Choose the correct Svelte syntax to pass a title prop to a child component and listen for a save event.

A&lt;Child [title]=pageTitle (save)=handleSave /&gt;
B&lt;Child :title="pageTitle" @save="handleSave" /&gt;
C&lt;Child title={pageTitle} on:save={handleSave} /&gt;
D&lt;Child bind:title={pageTitle} listen:save={handleSave} /&gt;
Attempts:
2 left
💡 Hint

Recall how Svelte uses curly braces for props and on:event for events.

🔧 Debug
advanced
2:00remaining
Why does this Svelte component fail to update the UI when the array changes?

Look at this Svelte code snippet:

<script>
  let items = [1, 2, 3];
  function addItem() {
    items.push(items.length + 1);
  }
</script>
<button on:click={addItem}>Add Item</button>
<ul>
  {#each items as item}
    <li>{item}</li>
  {/each}
</ul>

Clicking the button does not update the list. Why?

ABecause the <code>each</code> block requires a key to update properly.
BBecause Svelte does not detect changes when mutating arrays directly; you must assign a new array to trigger updates.
CBecause the <code>push</code> method is asynchronous and delays updates.
DBecause the <code>addItem</code> function is missing an <code>await</code> keyword.
Attempts:
2 left
💡 Hint

Think about how Svelte tracks changes to variables and arrays.

🧠 Conceptual
expert
3:00remaining
Which framework's design leads to smaller bundle sizes and faster startup times?

Between Svelte, React, and Vue, which framework's design inherently produces smaller JavaScript bundles and faster page load times, and why?

ASvelte, because it compiles components at build time into minimal JavaScript without a runtime virtual DOM.
BReact, because its virtual DOM diffing reduces the amount of JavaScript needed at runtime.
CVue, because it uses a template compiler that eliminates the need for JavaScript in the browser.
DAll three produce similar bundle sizes because they all use virtual DOMs.
Attempts:
2 left
💡 Hint

Consider which framework does most work before the browser runs the code.