Bird
0
0

Consider these selectors:

medium📝 state output Q5 of 15
Angular - State Management
Consider these selectors:
const selectCart = (state) => state.cart;
const selectCartCount = createSelector(selectCart, cart => cart.items.length);

What is the output of selectCartCount if state.cart.items is ['apple', 'banana']?
A2
B'2'
Cundefined
DNaN
Step-by-Step Solution
Solution:
  1. Step 1: Identify input selector output

    selectCart returns the cart object with items array.
  2. Step 2: Calculate length in derived selector

    selectCartCount returns the length of the items array, which is 2.
  3. Final Answer:

    2 -> Option A
  4. Quick Check:

    Array length returns number count [OK]
Quick Trick: Array length returns number, not string [OK]
Common Mistakes:
  • Returning string '2' instead of number
  • Confusing undefined with zero
  • Expecting NaN from length

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes