<script> let dataPromise = new Promise((resolve) => { setTimeout(() => resolve('Hello from promise!'), 2000); }); </script> <p>{#await dataPromise} Loading... {:then data} {data} {/await}</p>
The #await block shows the content inside it before the promise resolves. So initially, it shows "Loading..." until the promise finishes.
<script> let promise = new Promise((res) => setTimeout(() => res('Data loaded'), 1000)); </script> {#await promise} <p>Waiting...</p> {:then result} <p>{result}</p> {/await}
After the promise resolves, the {:then} block runs and displays the resolved value inside a paragraph.
Option D correctly calls the function and uses {:then data} to capture the resolved value. Option D misses parentheses, C misses {:then} block, and D misses the variable name after then.
<script> let promise = fetch('/api/data').then(res => res.json()); </script> {#await promise} <p>Loading...</p> {:then data} <p>{data.message}</p> {/await}
The error happens because data.message is accessed but the API response does not contain a 'message' property, causing a runtime error.
<script> let promise = new Promise((_, reject) => setTimeout(() => reject('Failed'), 1000)); </script> {#await promise} <p>Loading...</p> {:then data} <p>{data}</p> {/await}
If a promise rejects and there is no {:catch} block, Svelte throws an error and the component crashes, showing an error in the console.
