Docsity

Angular Fundamentals Ultimate Exam, Exams of Technology

Toggle sidebar
bg1
Angular Fundamentals Ultimate
Exam
Question 1. **What is the primary purpose of a standalone component in
Angular 15+?**
A) To replace services with components
B) To eliminate the need for NgModules
C) To provide a new routing strategy
D) To enable server-side rendering only
Answer: B
Explanation: Standalone components are self-contained units that can be
declared without being part of an NgModule, simplifying the module system.
---
Question 2. **In angular.json, which property defines the entry point for the
application’s TypeScript compilation?**
A) "assets"
B) "styles"
C) "main"
D) "outputPath"
Answer: C
Explanation: The "main" property points to the file (typically src/main.ts) that
bootstraps the Angular app, initiating the TypeScript compilation.
---
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48

Partial preview of the text

Download Angular Fundamentals Ultimate Exam and more Exams Technology in PDF only on Docsity!

Exam

Question 1. What is the primary purpose of a standalone component in Angular 15+? A) To replace services with components B) To eliminate the need for NgModules C) To provide a new routing strategy D) To enable server-side rendering only Answer: B Explanation: Standalone components are self-contained units that can be declared without being part of an NgModule, simplifying the module system.

Question 2. In angular.json, which property defines the entry point for the application’s TypeScript compilation? A) "assets" B) "styles" C) "main" D) "outputPath" Answer: C Explanation: The "main" property points to the file (typically src/main.ts) that bootstraps the Angular app, initiating the TypeScript compilation.

Exam

Question 3. Which compilation mode generates component factories at build time, resulting in faster runtime performance? A) JIT (Just-in-Time) B) AOT (Ahead-of-Time) C) Ivy only D) ViewEngine Answer: B Explanation: AOT compiles templates into JavaScript factories during the build, removing the need for runtime compilation and improving load time.

Question 4. Which TypeScript decorator is used to define metadata for an Angular component? A) @Injectable B) @Pipe C) @Component D) @Directive Answer: C Explanation: @Component decorates a class with metadata such as selector, template, and styles, turning it into an Angular component.

Question 5. When using the Emulated view encapsulation, how does Angular emulate Shadow DOM behavior?

Exam

B) To improve performance by tracking items via a unique identifier C) To debounce user input inside the loop D) To automatically paginate the list Answer: B Explanation: trackBy tells Angular how to identify items, preventing unnecessary DOM re-creation when the collection changes.

Question 8. Which syntax represents two-way data binding in Angular’s template syntax? A) [value]="name" (input)="name=$event" B) {{ name }} C) [(ngModel)]="name" D) bind-value="name" Answer: C Explanation: [(ngModel)] combines property and event binding to achieve two-way data binding.

Question 9. How does the new signal-based input API differ from the classic @Input property? A) It removes the need for change detection entirely B) It provides a reactive Signal object that updates automatically

Exam

C) It forces the component to re-render on every change D) It only works with template-driven forms Answer: B Explanation: input() returns a Signal that reflects the latest value, enabling reactive consumption without explicit change detection.

Question 10. Which Angular feature enables content projection into a component’s template? A) @ViewChild B) ngModel C) D) Renderer Answer: C Explanation: acts as a placeholder for projected content from the component’s consumer.

Question 11. What does the signal() function create in Angular’s Signals API? A) An Observable that emits values over time B) A mutable reactive primitive that holds a value C) A static constant that cannot change

Exam

Answer: A Explanation: Zoneless Angular relies on explicit signals and effects instead of zone.js patches, reducing overhead.

Question 14. Which RxJS operator is best suited for cancelling previous inner Observables when a new source emission arrives? A) map B) filter C) switchMap D) mergeMap Answer: C Explanation: switchMap unsubscribes from the previous inner Observable whenever the outer Observable emits a new value.

Question 15. When using the async pipe, what happens if the underlying Observable completes? A) The pipe throws an error B) The view displays “null” C) The latest emitted value remains displayed D) The component is destroyed Answer: C

Exam

Explanation: async pipe retains the last emitted value after completion, keeping it rendered until the source changes.

Question 16. Which built-in pipe would you use to format a number as US currency? A) date B) json C) currency D) slice Answer: C Explanation: The currency pipe formats numbers as monetary values, defaulting to the locale’s currency unless specified.

Question 17. What is the main difference between a pure and an impure pipe? A) Pure pipes run only when their input reference changes; impure pipes run on every change detection cycle B) Pure pipes can be used only in templates, impure pipes only in code C) Pure pipes are asynchronous, impure pipes are synchronous D) Pure pipes are deprecated Answer: A

Exam

Explanation: inject() allows direct retrieval of a dependency inside any class or function, removing the need for constructor parameters.

Question 20. When creating an InjectionToken, which generic type argument should you provide? A) The token’s name string B) The type of the value the token resolves to C) The Angular version D) The provider’s scope Answer: B Explanation: The generic type parameter defines the shape of the value associated with the token, enabling type-safe injection.

Question 21. Which router configuration property defines a fallback route for unknown URLs? A) pathMatch: 'full' B) redirectTo: '' C) path: '' D) canActivate: [''] Answer: C Explanation: A route with path '' matches any URL not matched earlier, acting as a wildcard fallback.

Exam

Question 22. What is the purpose of a CanDeactivate guard? A) To prevent navigation to a route if the user is unauthenticated B) To fetch data before a route activates C) To ask the user for confirmation before leaving a component D) To lazy-load a module Answer: C Explanation: CanDeactivate runs when leaving a route, allowing the component to decide whether navigation should proceed (e.g., unsaved changes).

Question 23. Which method on the Router service navigates programmatically while preserving query parameters? A) navigateByUrl() B) navigate() with { queryParamsHandling: 'preserve' } C) go() D) reload() Answer: B Explanation: The navigate() method accepts an options object; setting queryParamsHandling to 'preserve' retains existing query parameters.

Exam

Question 26. What is the return type of a synchronous validator function? A) Observable B) Promise C) ValidationErrors | null D) void Answer: C Explanation: Synchronous validators return either a ValidationErrors object (if invalid) or null (if valid).

Question 27. Which lifecycle hook is called after Angular has fully rendered the component’s view for the first time? A) ngOnInit B) ngAfterViewInit C) ngDoCheck D) ngOnChanges Answer: B Explanation: ngAfterViewInit runs after the component’s view (and child views) are initialized and rendered.

Question 28. What does the Angular Universal engine provide?

Exam

A) Client-side only rendering B) Server-side rendering (SSR) for Angular apps C) Automatic code splitting for lazy loading D) A new state management library Answer: B Explanation: Angular Universal enables rendering Angular applications on the server, improving SEO and first-paint performance.

Question 29. Which new decorator enables deferring the loading of a component until a specific trigger occurs? A) @Lazy B) @Defer C) @defer D) @AsyncComponent Answer: C Explanation: The @defer decorator (or ) tells Angular to load a component lazily based on triggers like viewport entry or idle time.

Question 30. When using ChangeDetectionStrategy.OnPush, which of the following will NOT trigger change detection? A) Input property reference change

Exam

D) The routing configuration Answer: B Explanation: The Signals tab shows each Signal’s current value and the effect graph, helping developers debug reactive state.

Question 33. Which property in angular.json controls the file replacements for different build configurations? A) "fileReplacements" B) "assets" C) "styles" D) "scripts" Answer: A Explanation: "fileReplacements" maps source files (e.g., environment.ts) to alternative versions (e.g., environment.prod.ts) per configuration.

Question 34. **What does the “preserveWhitespaces” compiler option affect? ** A) Whether TypeScript removes comments B) Whether Angular retains whitespace in component templates during compilation C) Whether CSS is minified D) Whether source maps are generated

Exam

Answer: B Explanation: preserveWhitespaces:true keeps whitespace as written in templates, which can affect layout and rendering.

Question 35. Which decorator marks a class as a custom attribute directive? A) @Component B) @Pipe C) @Directive D) @NgModule Answer: C Explanation: @Directive is used for both structural and attribute directives, defining selector and host bindings.

Question 36. How can you apply multiple CSS classes conditionally using Angular’s built-in directive? A) [style]="{'class1': condition}" B) [class]="{'class1 class2': condition}" C) [ngClass]="{'class1': condition1, 'class2': condition2}" D) ngClass="class1 class2"

Exam

Explanation: combineLatest emits a new array whenever any source Observable emits, using the latest values from all sources.

Question 39. When using a resolver, at which point does Angular wait for the data to be fetched? A) After the component’s ngOnInit runs B) Before the route is activated and the component is instantiated C) During the component’s change detection cycle D) Only when the user clicks a button Answer: B Explanation: Resolvers run during navigation; the router waits for them to complete before activating the route and creating the component.

Question 40. What does the “runGuardsAndResolvers” option set to “always” do? A) Prevents any guard or resolver from executing after the first navigation B) Forces guards and resolvers to run on every navigation, even if the route parameters haven’t changed C) Executes guards only on lazy-loaded modules D) Disables all guards and resolvers Answer: B

Exam

Explanation: Setting runGuardsAndResolvers:'always' makes Angular re-run guards and resolvers on each navigation to the same route.

Question 41. Which method on FormGroup adds a new FormControl at runtime? A) push() B) addControl() C) insert() D) createControl() Answer: B Explanation: FormGroup.addControl(name, control) registers a new FormControl under the specified key.

Question 42. In a reactive form, how do you set a validator that runs asynchronously (e.g., checking a username’s uniqueness on the server)? A) Pass a Promise directly to the FormControl constructor B) Use the asyncValidators option when creating the FormControl C) Set the validator in the template with ngModelAsync D) Async validators are not supported in reactive forms Answer: B Explanation: The asyncValidators array in the FormControl options registers asynchronous validator functions that return a Promise or Observable.