Programming MCQs Feed

📊 Angular
Q. Which operator shares a single subscription among multiple subscribers?
  • (A) map
  • (B) shareReplay
  • (C) filter
  • (D) delay
💬 Discuss
✅ Correct Answer: (B) shareReplay

Explanation: shareReplay shares and replays emitted values.

📊 Angular
Q. Which Angular testing utility creates a test environment?
  • (A) TestBed
  • (B) Jasmine
  • (C) Karma
  • (D) Protractor
💬 Discuss
✅ Correct Answer: (A) TestBed

Explanation: TestBed configures the Angular testing module.

📊 Angular
Q. What does the inject() function replace?
  • (A) NgModule
  • (B) Constructor-based dependency injection
  • (C) Services
  • (D) Providers
💬 Discuss
✅ Correct Answer: (B) Constructor-based dependency injection

Explanation: inject() allows DI without constructors.

📊 Angular
Q. Which Angular feature enables hydration in SSR?
  • (A) Zone.js
  • (B) TransferState
  • (C) NgModule
  • (D) HttpClient
💬 Discuss
✅ Correct Answer: (B) TransferState

Explanation: TransferState helps transfer data from server to client.

📊 Angular
Q. What does the router-outlet directive do?
  • (A) Loads services
  • (B) Acts as placeholder for routed views
  • (C) Handles guards
  • (D) Preloads modules
💬 Discuss
✅ Correct Answer: (B) Acts as placeholder for routed views

Explanation: router-outlet displays routed components.

📊 Angular
Q. Which lifecycle hook is called when an input property changes?
  • (A) ngOnInit
  • (B) ngDoCheck
  • (C) ngOnChanges
  • (D) ngAfterViewInit
💬 Discuss
✅ Correct Answer: (C) ngOnChanges

Explanation: ngOnChanges reacts to @Input() changes.

📊 Angular
Q. Which operator is used to handle errors in RxJS?
  • (A) catchError
  • (B) throwError
  • (C) retry
  • (D) finalize
💬 Discuss
✅ Correct Answer: (A) catchError

Explanation: catchError handles observable errors.

📊 Angular
Q. Which Angular feature supports tree shaking?
  • (A) NgModules
  • (B) providedIn
  • (C) Two-way binding
  • (D) Event emitters
💬 Discuss
✅ Correct Answer: (B) providedIn

Explanation: providedIn enables tree-shakable providers.

📊 Angular
Q. Which API is used to dynamically create components?
  • (A) ComponentFactoryResolver
  • (B) Renderer2
  • (C) ViewEncapsulation
  • (D) TemplateRef
💬 Discuss
✅ Correct Answer: (A) ComponentFactoryResolver

Explanation: ComponentFactoryResolver dynamically creates components.

📊 Angular
Q. What is the main purpose of ChangeDetectionStrategy.OnPush?
  • (A) Runs change detection on every event
  • (B) Improves performance by reducing change detection cycles
  • (C) Disables change detection completely
  • (D) Works only with services
💬 Discuss
✅ Correct Answer: (B) Improves performance by reducing change detection cycles

Explanation: OnPush runs change detection only when input references change or events occur.