Why should Svelte component names start with a capital letter?
Starting component names with a capital letter helps Svelte and developers distinguish components from regular HTML elements. It improves readability and prevents naming conflicts.
Click to reveal answer
beginner
What is the recommended file naming style for Svelte components?
Svelte components should be saved with PascalCase file names, like MyComponent.svelte. This matches the component name and helps keep the project organized.
Click to reveal answer
intermediate
How should you name components that represent UI elements versus pages in Svelte?
UI elements usually have descriptive names like Button or Modal. Pages often use names that reflect their route or purpose, like HomePage or UserProfile.
Click to reveal answer
beginner
What naming style is NOT recommended for Svelte components?
Using lowercase or kebab-case (like my-component.svelte) for component files is not recommended because it can confuse Svelte and developers, making it harder to identify components.
Click to reveal answer
intermediate
Why is consistent component naming important in Svelte projects?
Consistent naming makes the code easier to read, maintain, and scale. It helps new team members understand the project quickly and reduces errors caused by misnaming.
Click to reveal answer
Which of these is the correct way to name a Svelte component file?
AUserProfile.svelte
Buserprofile.svelte
Cuser-profile.svelte
Duser_profile.svelte
✗ Incorrect
Svelte components should use PascalCase file names matching the component name, like UserProfile.svelte.
Why should component names start with a capital letter in Svelte?
ATo avoid using quotes
BTo make the file size smaller
CTo improve performance
DTo distinguish components from HTML tags
✗ Incorrect
Capital letters help distinguish components from regular HTML elements, improving clarity.
Which naming style is discouraged for Svelte components?
APascalCase
BcamelCase
Ckebab-case
DUpperCamelCase
✗ Incorrect
kebab-case is discouraged because it can confuse Svelte and developers when identifying components.
What is a good practice when naming page components in Svelte?
AUse random names
BUse names that reflect the page's purpose
CUse all lowercase letters
DUse numbers only
✗ Incorrect
Page components should have descriptive names that reflect their purpose, like HomePage or UserProfile.
Consistent component naming helps with:
ACode readability and maintenance
BIncreasing file size
CSlowing down the app
DMaking code harder to understand
✗ Incorrect
Consistent naming improves readability, maintenance, and teamwork.
Explain why Svelte components should be named using PascalCase and start with a capital letter.
Think about how you tell a friend apart from a place by their names.
You got /3 concepts.
Describe the difference in naming conventions between UI element components and page components in Svelte.
Consider how you name small tools versus big rooms in a house.
You got /3 concepts.
Practice
(1/5)
1. Which naming style is recommended for Svelte component files and their names?
easy
A. kebab-case (e.g., my-component.svelte)
B. snake_case (e.g., my_component.svelte)
C. PascalCase (e.g., MyComponent.svelte)
D. all lowercase (e.g., mycomponent.svelte)
Solution
Step 1: Understand Svelte naming conventions
Svelte recommends using PascalCase for component names and file names to clearly distinguish components from regular HTML tags.
Step 2: Compare naming styles
PascalCase capitalizes the first letter of each word, making component names easy to read and recognize, unlike snake_case, kebab-case, or all lowercase.
Final Answer:
PascalCase (e.g., MyComponent.svelte) -> Option C
Quick Check:
Component names use PascalCase [OK]
Hint: Always capitalize each word in component names [OK]
Common Mistakes:
Using kebab-case which is for HTML attributes
Using snake_case which is uncommon in Svelte
Using all lowercase which looks like regular HTML tags
2. Which of the following is a correct Svelte component file name?
easy
A. userprofile.svelte
B. user_profile.svelte
C. user-profile.svelte
D. UserProfile.svelte
Solution
Step 1: Check file naming rules for Svelte components
Svelte components should be named using PascalCase to clearly identify them as components.
Step 2: Identify the PascalCase option
Among the options, only UserProfile.svelte uses PascalCase correctly.
Final Answer:
UserProfile.svelte -> Option D
Quick Check:
PascalCase file name = UserProfile.svelte [OK]
Hint: Look for capital letters starting each word in the file name [OK]
Common Mistakes:
Using lowercase or underscores instead of PascalCase
Confusing kebab-case with component file naming
Mixing styles inconsistently
3. Given the component file named LoginForm.svelte, which is the correct way to import and use it in another Svelte file?
medium
A.
import LoginForm from './LoginForm.svelte';
<LoginForm />
B.
import loginform from './LoginForm.svelte';
<LoginForm />
C.
import LoginForm from './loginform.svelte';
<loginForm />
D.
import loginForm from './LoginForm.svelte';
<loginForm />
Solution
Step 1: Match import name with component file name
The import name should match the PascalCase component file name exactly, including capitalization.
Step 2: Use the imported component with correct casing
In Svelte, component tags must start with uppercase letters matching the import name.
Final Answer:
import LoginForm from './LoginForm.svelte';
<LoginForm /> -> Option A
Quick Check:
Import and usage use PascalCase consistently [OK]
Hint: Import and use components with exact PascalCase names [OK]
Common Mistakes:
Importing with lowercase names
Using lowercase component tags
Mismatching import path casing
4. What is wrong with this Svelte component file name and usage?
A. The filename should be PascalCase to match the component usage.
B. The component tag should be lowercase to match the filename.
C. The filename should use kebab-case instead of lowercase.
D. There is no issue; this is valid Svelte usage.
Solution
Step 1: Check filename casing
The filename userprofile.svelte is all lowercase, which is not recommended for Svelte components.
Step 2: Check component usage casing
The usage <UserProfile /> uses PascalCase, which expects the filename to match in PascalCase.
Final Answer:
The filename should be PascalCase to match the component usage. -> Option A
Quick Check:
Filename and usage casing must match PascalCase [OK]
Hint: Filename and usage must both be PascalCase [OK]
Common Mistakes:
Using lowercase filenames with PascalCase tags
Assuming kebab-case is valid for component files
Ignoring case sensitivity in imports
5. You have two components: NavBar.svelte and navBar.svelte. What problem might this cause in a Svelte project on a case-sensitive file system?
hard
A. The project will fail to compile due to duplicate component names.
B. Only one component will be recognized; the other will be ignored or cause confusion.
C. Both components will work fine since Svelte ignores filename case.
D. The components will merge automatically into one component.
Solution
Step 1: Understand case sensitivity in file systems
On case-sensitive systems (like Linux), NavBar.svelte and navBar.svelte are different files but can cause confusion in imports.
Step 2: Recognize Svelte import and usage issues
Importing components with inconsistent casing can cause one component to be ignored or cause runtime errors because Svelte expects consistent PascalCase naming.
Final Answer:
Only one component will be recognized; the other will be ignored or cause confusion. -> Option B
Quick Check:
Case-sensitive filenames cause import confusion [OK]
Hint: Avoid similar names differing only by case [OK]
Common Mistakes:
Assuming case-insensitive systems behave the same everywhere
Using inconsistent casing in imports and filenames
Expecting automatic merging of components
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.