0
0
Svelteframework~20 mins

Component naming conventions in Svelte - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Svelte Component Naming Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why should Svelte components start with a capital letter?
In Svelte, why is it important to name components starting with a capital letter?
ABecause lowercase names are reserved for CSS classes in Svelte.
BBecause lowercase names cause the component to be ignored during compilation.
CBecause only capitalized names can use reactive statements inside the component.
DBecause Svelte treats capitalized names as components and lowercase as HTML elements.
Attempts:
2 left
💡 Hint
Think about how Svelte distinguishes between HTML tags and components.
📝 Syntax
intermediate
1:00remaining
Identify the correctly named Svelte component file
Which of the following file names follows the recommended Svelte component naming conventions?
AUserProfile.svelte
Buser_profile.svelte
CuserProfile.svelte
Duserprofile.svelte
Attempts:
2 left
💡 Hint
Component files should start with a capital letter and use PascalCase.
component_behavior
advanced
2:00remaining
What happens if you import a Svelte component with a lowercase name?
Consider this code snippet:
import header from './Header.svelte';

<header />

What will be the rendered output in the browser?
Svelte
import header from './Header.svelte';

<header />
AThe browser renders the HTML &lt;header&gt; element, ignoring the imported component.
BThe Header component renders correctly as expected.
CA runtime error occurs because the component name is lowercase.
DNothing renders because the component is not recognized.
Attempts:
2 left
💡 Hint
Remember how Svelte treats lowercase tags in markup.
🔧 Debug
advanced
2:00remaining
Find the error in this Svelte component import and usage
What error will this Svelte code produce?
import navbar from './Navbar.svelte';

<Navbar />
Svelte
import navbar from './Navbar.svelte';

<Navbar />
ANo error; component renders correctly.
BSyntaxError due to incorrect component usage syntax.
CReferenceError: Navbar is not defined because the import name is lowercase but usage is capitalized.
DTypeError: Cannot render component because of case mismatch.
Attempts:
2 left
💡 Hint
Check if the imported name matches the used component name exactly.
state_output
expert
2:30remaining
What is the output of this Svelte component with mixed case naming?
Given the component file named MyButton.svelte with this code:
<script>
  export let label = 'Click';
</script>

<button>{label}</button>

And this usage in another component:
import mybutton from './MyButton.svelte';

<mybutton label="Press" />

What will be displayed on the page?
Svelte
import mybutton from './MyButton.svelte';

<mybutton label="Press" />
AThe text 'Press' inside a button rendered by the MyButton component.
BNothing renders because 'mybutton' is lowercase and treated as an unknown HTML tag.
CThe literal text '<mybutton label="Press" />' appears on the page.
DA runtime error occurs due to incorrect component naming.
Attempts:
2 left
💡 Hint
Recall how Svelte treats lowercase tags in markup and component imports.