Consider how Svelte, React, and Vue update the webpage when data changes. Which statement best describes Svelte's approach?
Think about whether Svelte uses a virtual DOM or compiles away the framework.
Svelte compiles your code into small, efficient JavaScript that updates the DOM directly. Unlike React and Vue, it does not use a virtual DOM, which makes updates faster and smaller.
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>Remember how Svelte tracks reactive variables and updates the UI immediately.
Svelte tracks changes to variables like count automatically. When you click the button, count increases and the UI updates right away without needing extra hooks.
Choose the correct Svelte syntax to pass a title prop to a child component and listen for a save event.
Recall how Svelte uses curly braces for props and on:event for events.
Svelte uses curly braces to pass props and the on:event directive to listen to events. Option C follows this pattern correctly.
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?
Think about how Svelte tracks changes to variables and arrays.
Svelte tracks assignments to variables. Mutating an array with push does not trigger reactivity. You must assign a new array, for example: items = [...items, newItem].
Between Svelte, React, and Vue, which framework's design inherently produces smaller JavaScript bundles and faster page load times, and why?
Consider which framework does most work before the browser runs the code.
Svelte compiles your code ahead of time into efficient JavaScript that updates the DOM directly. This removes the need for a large runtime library and virtual DOM, resulting in smaller bundles and faster startup.