Bird
0
0

Identify the error in the following code snippet using computed signals:

medium📝 Debug Q14 of 15
Angular - Signals
Identify the error in the following code snippet using computed signals:
const price = signal(100);
const tax = signal(0.1);
const total = computed(() => price + tax * price);

console.log(total());
AComputed signals cannot use arithmetic operations
BSignals must be called as functions inside computed
CSignals cannot be used inside computed
DMissing initial value for tax signal
Step-by-Step Solution
Solution:
  1. Step 1: Check how signals are accessed

    Signals are functions and must be called with () to get their current value.
  2. Step 2: Analyze the computed expression

    The expression uses price and tax directly without calling them, so it uses the signal objects, not their values.
  3. Final Answer:

    Signals must be called as functions inside computed -> Option B
  4. Quick Check:

    Access signals with () inside computed [OK]
Quick Trick: Always call signals as functions inside computed [OK]
Common Mistakes:
  • Using signal variables directly without ()
  • Thinking computed disallows arithmetic
  • Ignoring signal initial values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes