Consider this Astro page component code:
---
const title = "Welcome to Astro!";
---
{title}
{title}
What will the browser display inside the <h1> tag?
--- const title = "Welcome to Astro!"; --- <html lang="en"> <head> <title>{title}</title> </head> <body> <h1>{title}</h1> </body> </html>
Remember Astro uses frontmatter variables inside curly braces to insert values.
The variable title is defined in the frontmatter and inserted correctly inside the <h1> tag, so the output is the string value.
You want to create a new page accessible at /about. Which file and content is correct?
Astro uses the src/pages folder for routing pages.
Astro automatically routes files inside src/pages. The file about.astro creates the /about page.
Given this Astro page code:
---
let count = 0;
function increment() {
count += 1;
}
---
Count: {count}
What happens when you click the button?
--- let count = 0; function increment() { count += 1; } --- <html lang="en"> <body> <p>Count: {count}</p> <button on:click={increment}>Add</button> </body> </html>
Astro pages are static by default and do not update state on the client without client directives.
Astro renders static HTML by default. The count variable changes in code but the page does not re-render on click without client hydration.
Look at this Astro page code:
---
const message = "Hello";
---
{message}
What is the cause of the build failure?
--- const message = "Hello"; --- <html lang="en"> <body> <h1>{message}</h1> </body> </html>
Check the HTML tags carefully for matching pairs.
The opening tag is <h1> but the closing tag is </h2>. This mismatch causes a build error.
Given this folder structure:
src/pages/
blog/
index.astro
[slug].astro
about.astroWhich statement best describes the URLs generated by Astro?
Astro uses file and folder names to create routes automatically, including dynamic segments.
Astro maps index.astro in a folder to the folder path, and [slug].astro creates a dynamic route segment.
