Bird
0
0

Which of the following is a correct signature for a trackBy function used in ngFor?

easy📝 Conceptual Q2 of 15
Angular - Performance Optimization
Which of the following is a correct signature for a trackBy function used in ngFor?
A(item: any, index: number) => string
B(item: any) => void
C(index: number, item: any) => any
D(index: string, item: any) => boolean
Step-by-Step Solution
Solution:
  1. Step 1: Recall the trackBy function signature

    The trackBy function receives the index (number) and the item (any type) and returns a unique identifier.
  2. Step 2: Match the correct parameter types and return type

    (index: number, item: any) => any matches the signature: it takes (index: number, item: any) and returns any unique value.
  3. Final Answer:

    (index: number, item: any) => any -> Option C
  4. Quick Check:

    trackBy signature = (number, any) => any [OK]
Quick Trick: trackBy function takes index and item, returns unique id [OK]
Common Mistakes:
  • Swapping parameter order
  • Using wrong parameter types
  • Returning void or boolean instead of unique id

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes