Bird
0
0

What is wrong with this Angular template expression?

medium📝 Debug Q14 of 15
Angular - Pipes
What is wrong with this Angular template expression?
{{ 123 | uppercase | slice:0:2 }}
ANumbers cannot be used with pipes
BThere is no error; this works fine
CThe <code>uppercase</code> pipe cannot be applied to a number
DThe <code>slice</code> pipe requires a string input
Step-by-Step Solution
Solution:
  1. Step 1: Check the first pipe uppercase usage

    Angular's uppercase pipe coerces the input to a string first (123 becomes '123'), then applies toUpperCase(), resulting in '123'.
  2. Step 2: Apply the second pipe slice:0:2

    On '123', slice from 0 to 2 gives '12'. No error occurs.
  3. Final Answer:

    There is no error; this works fine -> Option B
  4. Quick Check:

    Uppercase coerces number to string, then slice works [OK]
Quick Trick: Angular pipes like uppercase coerce non-strings to string [OK]
Common Mistakes:
  • Thinking uppercase strictly requires string input without coercion
  • Believing numbers cause runtime errors in pipes
  • Assuming slice would fail due to input type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes