Web Development Frameworks 2 — Questions and Answers
Question 1: In Vue.js, which directive is used to bind data to an HTML attribute?
- v-model
- v-bind (Correct answer)
- v-attr
- v-data
Correct answer: v-bind
v-bind dynamically binds one or more attributes to an expression, while v-model is specifically for two-way form input binding.
Question 2: What is the purpose of Angular's NgModule decorator?
- To define a component's template
- To configure dependency injection tokens
- To declare and organize a cohesive block of application functionality (Correct answer)
- To create HTTP interceptors
Correct answer: To declare and organize a cohesive block of application functionality
NgModule organizes components, directives, and pipes into cohesive blocks and configures the injector and compiler.
Question 3: Which React hook should you use to run a side effect only once after the initial render?
- useEffect with no dependency array
- useEffect with an empty dependency array [] (Correct answer)
- useLayoutEffect with null
- useMemo with []
Correct answer: useEffect with an empty dependency array []
Passing an empty array [] as the second argument to useEffect tells React to run the effect only after the first render.
Question 4: In Next.js, what does the `getStaticPaths` function do?
- Fetches data at request time for dynamic routes
- Specifies which dynamic route paths to pre-render at build time (Correct answer)
- Generates API routes automatically
- Configures middleware for path matching
Correct answer: Specifies which dynamic route paths to pre-render at build time
getStaticPaths defines the list of paths that will be statically generated for pages with dynamic route segments.
Question 5: What is Vuex primarily used for in Vue.js applications?
- Server-side rendering
- Centralized state management (Correct answer)
- Component routing
- Form validation
Correct answer: Centralized state management
Vuex is a state management pattern and library for Vue.js applications that serves as a centralized store for all component states.
Question 6: In Express.js, what does `app.use()` do?
- Defines a GET route handler
- Mounts middleware functions at a specified path (Correct answer)
- Starts the HTTP server
- Configures template engines
Correct answer: Mounts middleware functions at a specified path
app.use() mounts middleware functions that execute on every request or requests matching a specified path prefix.
Question 7: Which Angular feature allows you to lazy-load feature modules?
- RouterModule with loadChildren (Correct answer)
- NgModule with lazyLoad flag
- CommonModule with defer
- HttpClientModule with async
Correct answer: RouterModule with loadChildren
RouterModule's loadChildren property accepts a dynamic import that Angular uses to lazy-load the module only when that route is activated.
In Vue.js, which directive is used to bind data to an HTML attribute?