Loading

Quipoin Menu

Learn • Practice • Grow

angular / ngFor Directive
mcq
Direction: Choose the correct option

Q1.

What does `*ngFor='let item of items'` do?
A. Sorts an array
B. Creates a for loop in TypeScript
C. Iterates over a collection and renders a template for each item
D. Filters an array
Direction: Choose the correct option

Q2.

How do you get the index in `*ngFor`?
A. `*ngFor='let item of items; let i=index'`
B. `*ngFor='let item of items; index as i'`
C. `*ngFor='let item of items with index'`
D. Both A and B
Direction: Choose the correct option

Q3.

What is the purpose of `trackBy` in `*ngFor`?
A. To filter the list
B. To sort the list
C. To track errors
D. To optimize performance by tracking items by a unique identifier
Direction: Choose the correct option

Q4.

What happens if the array changes after initial render?
A. An error is thrown
B. Angular updates the DOM to reflect the changes
C. Nothing happens
D. The list remains static
Direction: Choose the correct option

Q5.

Can you use `*ngFor` with an object's properties?
A. No, only with arrays
B. Only with Maps
C. Only with Sets
D. Yes, using `KeyValuePipe`
Direction: Choose the correct option

Q6.

What are the local variables available in `*ngFor`?
A. count, start, end
B. index, first, last, even, odd
C. key, value
D. position, length
Direction: Choose the correct option

Q7.

What does `*ngFor='let item of items; trackBy: trackByFn'` do?
A. Tracks the function
B. Tracks items
C. Uses trackByFn to identify items uniquely
D. Tracks errors
Direction: Choose the correct option

Q8.

How do you loop a specific number of times (e.g., 5 times)?
A. `*ngFor='let i of [].constructor(5); let index=index'`
B. `*ngFor='let i of 5'`
C. `*ngFor='let i = 0; i < 5; i++'`
D. Not possible
Direction: Choose the correct option

Q9.

What is the role of `` with `*ngFor`?
A. To hide elements
B. To group elements without adding extra DOM nodes
C. To store items
D. To contain the loop
Direction: Choose the correct option

Q10.

What happens if you don't use `trackBy` with a list that changes frequently?
A. The list doesn't update
B. The entire list may be re-rendered, causing performance issues
C. Nothing special
D. Errors occur