Consider this Svelte component code:
<script>
let count = 2;
</script>
<h1>Count is {count * 3}</h1>
<style>
h1 { color: blue; }
</style>What will you see on the page?
<script> let count = 2; </script> <h1>Count is {count * 3}</h1> <style> h1 { color: blue; } </style>
Remember the expression inside curly braces is evaluated.
The variable count is 2, multiplied by 3 gives 6. The style sets the heading color to blue.
Which of these script sections is valid in a Svelte component?
Look for correct attribute syntax and placement.
The script tag with no attributes is the component instance script where export let declares props. The context="module" script is for module-level code and cannot export props.
Given this Svelte component:
<script>
let color = 'red';
</script>
<h2 class="title">Hello</h2>
<style>
.title { color: {color}; }
</style>Why does the heading not appear red?
<script> let color = 'red'; </script> <h2 class="title">Hello</h2> <style> .title { color: {color}; } </style>
Think about how CSS and JavaScript interact in Svelte.
Svelte does not allow JavaScript variables inside CSS blocks directly. To use dynamic styles, you must use inline styles or CSS variables.