-
What is Next.js primarily known as?
- A CSS framework
- A React framework for building web applications
- A database management system
- A programming language
Correct Answer: A React framework for building web applications
Explanation: Next.js is a popular open-source React framework that provides building blocks to create fast web applications.
-
Which company maintains Next.js?
- Facebook
- Google
- Vercel
- Microsoft
Correct Answer: Vercel
Explanation: Next.js is developed and maintained by Vercel.
-
In the Next.js App Router, which file is used to define the UI for a specific route?
- route.js
- page.js
- index.js
- layout.js
Correct Answer: page.js
Explanation: In the App Router (Next.js 13+), the page.js file is used to define the unique UI for a route.
-
How do you create a dynamic route in Next.js?
- Using a dollar sign like $id.js
- Using curly braces like {id}.js
- Using square brackets like [id].js
- Using an underscore like _id.js
Correct Answer: Using square brackets like [id].js
Explanation: Dynamic segments are created by wrapping a folder or file name in square brackets, such as [id] or [slug].
-
What does SSR stand for in the context of Next.js?
- Static Site Resources
- Server-Side Rendering
- Simple State Router
- Sequential Site Recovery
Correct Answer: Server-Side Rendering
Explanation: SSR stands for Server-Side Rendering, where the HTML is generated on each request.
-
Which function is used in the Pages Router to fetch data for Static Site Generation (SSG)?
- getServerSideProps
- getStaticProps
- useEffect
- getInitialProps
Correct Answer: getStaticProps
Explanation: getStaticProps is used in the Pages Router to fetch data at build time for pre-rendering.
-
What is the purpose of the 'next/link' component?
- To link external CSS files
- To enable client-side navigation between routes
- To connect to a database
- To create a link to an external website only
Correct Answer: To enable client-side navigation between routes
Explanation: The Link component provides client-side navigation, allowing for faster transitions between pages without a full reload.
-
In the App Router, what is the default component type?
- Client Components
- Server Components
- Shared Components
- Static Components
Correct Answer: Server Components
Explanation: By default, all components inside the App Router are React Server Components.
-
Which directive is needed at the top of a file to make it a Client Component?
- 'use server'
- 'use client'
- 'client side'
- 'enable client'
Correct Answer: 'use client'
Explanation: The 'use client' directive is used to declare a boundary between Server and Client Components.
-
What does ISR stand for?
- Incremental Static Regeneration
- Instant Site Rendering
- Internal Server Response
- Integrated Static Routing
Correct Answer: Incremental Static Regeneration
Explanation: ISR allows you to update static content after you have built your site without needing to rebuild the entire site.
-
Which file is used to define a shared UI across multiple pages in the App Router?
- page.js
- template.js
- layout.js
- global.js
Correct Answer: layout.js
Explanation: layout.js is used to define a UI that is shared between multiple pages, preserving state and avoiding re-renders.
-
How can you optimize images in Next.js?
- Using the standard <img> tag
- Using the 'next/image' component
- By converting all images to GIF
- Next.js does not support image optimization
Correct Answer: Using the 'next/image' component
Explanation: The Image component in Next.js provides automatic image optimization, such as resizing and lazy loading.
-
Where should static assets like images and fonts be stored in a Next.js project?
- /assets
- /static
- /public
- /src
Correct Answer: /public
Explanation: The /public directory is used to store static assets that can be referenced starting from the base URL.
-
Which command is used to start the Next.js development server?
- next build
- next start
- next dev
- next run
Correct Answer: next dev
Explanation: 'next dev' starts the development server with Hot Module Replacement and error reporting.
-
Which function is used in the Pages Router for Server-Side Rendering (SSR)?
- getStaticProps
- getServerSideProps
- getStaticPaths
- useServerSide
Correct Answer: getServerSideProps
Explanation: getServerSideProps is called on every request to fetch data and render the page on the server.
-
What is the primary benefit of Automatic Static Optimization?
- It converts JavaScript to TypeScript
- It determines if a page can be rendered as static HTML
- It minifies CSS files automatically
- It handles user authentication
Correct Answer: It determines if a page can be rendered as static HTML
Explanation: Next.js automatically determines if a page can be pre-rendered as static HTML if it doesn't have blocking data requirements.
-
In the App Router, how do you handle metadata like page titles?
- Using the <Head> component from 'next/head'
- Exporting a 'metadata' object or 'generateMetadata' function
- Using a meta.json file
- Adding a <title> tag inside page.js
Correct Answer: Exporting a 'metadata' object or 'generateMetadata' function
Explanation: The App Router uses the Metadata API, where you export a static metadata object or a dynamic generateMetadata function.
-
Which folder is used for API routes in the Pages Router?
- /routes/api
- /api
- /pages/api
- /server/api
Correct Answer: /pages/api
Explanation: In the Pages Router, any file inside the folder pages/api is mapped to /api/* and treated as an API endpoint.
-
What happens during the 'Hydration' process?
- The server compiles the code
- React attaches event listeners to the static HTML sent by the server
- The browser downloads images
- The database is synchronized
Correct Answer: React attaches event listeners to the static HTML sent by the server
Explanation: Hydration is the process of React taking the static HTML generated by the server and making it interactive in the browser.
-
Which hook is used to access the router object in a Client Component?
- useRoute
- useNextRouter
- useRouter
- useNavigation
Correct Answer: useRouter
Explanation: The useRouter hook from 'next/navigation' (App Router) or 'next/router' (Pages Router) allows access to the router.
-
What is the purpose of the 'next/font' module?
- To download fonts from Google at runtime
- To automatically optimize and host custom and Google fonts
- To convert fonts to CSS paths
- To provide a library of icons
Correct Answer: To automatically optimize and host custom and Google fonts
Explanation: next/font optimizes fonts by hosting them with the application and removing external network requests.
-
Which file allows you to customize the global HTML document in the Pages Router?
- _app.js
- _document.js
- layout.js
- index.html
Correct Answer: _document.js
Explanation: In the Pages Router, _document.js is used to augment the application's <html> and <body> tags.
-
What is the advantage of using Next.js for SEO?
- It automatically submits sites to Google
- It provides pre-rendered HTML that search engines can easily crawl
- It makes websites load slower
- It encrypts all content
Correct Answer: It provides pre-rendered HTML that search engines can easily crawl
Explanation: Next.js pre-renders pages into HTML, which ensures that search engine crawlers can see the content immediately.
-
How do you define a loading state for a route segment in the App Router?
- Using a 'loading.js' file
- Using a 'spinner.js' file
- Using 'getLoadingProps'
- Wrap the component in a try/catch block
Correct Answer: Using a 'loading.js' file
Explanation: The App Router uses the 'loading.js' file to automatically wrap a page or nested segment in a React Suspense boundary.
-
What is the purpose of 'middleware.js' in Next.js?
- To connect to the database
- To run code before a request is completed
- To style the application
- To manage global state
Correct Answer: To run code before a request is completed
Explanation: Middleware allows you to run code before a request is completed, such as for authentication, redirects, or header manipulation.
-
Which command builds the application for production?
- next dev
- next production
- next build
- next compile
Correct Answer: next build
Explanation: The 'next build' command creates an optimized production build of your application.
-
What is 'Fast Refresh'?
- A button in the browser
- A Next.js feature that gives near-instant feedback for edits to React components
- A way to clear the cache
- A method to reload the database
Correct Answer: A Next.js feature that gives near-instant feedback for edits to React components
Explanation: Fast Refresh is a Next.js feature that provides instant feedback on code changes without losing component state.
-
In the App Router, how do you handle errors for a specific segment?
- Using 'error.js' file
- Using a 'fallback.js' file
- Next.js does not handle errors
- Using 'try-catch' in the layout
Correct Answer: Using 'error.js' file
Explanation: The 'error.js' file convention allows you to gracefully handle runtime errors in nested routes.
-
Which CSS support is built-in to Next.js by default?
- Only Tailwind CSS
- CSS Modules, Sass, and Global CSS
- Only inline styles
- No CSS support
Correct Answer: CSS Modules, Sass, and Global CSS
Explanation: Next.js has built-in support for Global CSS, CSS Modules (.module.css), and Sass.
-
What does the 'public' folder provide in terms of routing?
- Nothing, it is for internal use
- Files inside are served relative to the root URL (/)
- It contains the API routes
- It defines the private routes
Correct Answer: Files inside are served relative to the root URL (/)
Explanation: Assets in the 'public' folder, like 'public/logo.png', can be accessed directly at '/logo.png'.