Bird
0
0

Given this Angular component code, which part will be removed by tree shaking if unused?

medium📝 Predict Output Q4 of 15
Angular - Performance Optimization
Given this Angular component code, which part will be removed by tree shaking if unused?
import { Component } from '@angular/core';

@Component({ selector: 'app-test', template: '

Test

' }) export class TestComponent { usedMethod() { return 'used'; } unusedMethod() { return 'unused'; } }
AusedMethod()
BBoth methods
CNeither method
DunusedMethod()
Step-by-Step Solution
Solution:
  1. Step 1: Identify which methods are called

    Only usedMethod() is called or referenced; unusedMethod() is not.
  2. Step 2: Understand tree shaking effect

    Unused methods like unusedMethod() get removed to reduce bundle size.
  3. Final Answer:

    unusedMethod() -> Option D
  4. Quick Check:

    Unused code removed = unusedMethod() [OK]
Quick Trick: Unused methods get removed by tree shaking [OK]
Common Mistakes:
  • Assuming all methods stay regardless of usage
  • Thinking usedMethod() is removed
  • Believing tree shaking removes entire classes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes