Challenge - 5 Problems
Computed Signals Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Angular computed signal example?
Consider this Angular standalone component using signals and computed signals. What will be displayed inside the paragraph?
Angular
import { Component, computed, signal } from '@angular/core'; @Component({ selector: 'app-root', standalone: true, template: `<p>{{ fullName() }}</p>` }) export class AppComponent { firstName = signal('Jane'); lastName = signal('Doe'); fullName = computed(() => `${this.firstName()} ${this.lastName()}`); }
Attempts:
2 left
💡 Hint
Remember that computed signals are functions that return the derived value.
✗ Incorrect
The computed signal fullName combines firstName and lastName signals. Calling fullName() returns the concatenated string 'Jane Doe'.
❓ state_output
intermediate2:00remaining
What is the value of 'fullName' after updating signals?
Given this Angular component, what is the value returned by fullName() after the lastName signal is updated?
Angular
import { Component, computed, signal } from '@angular/core'; @Component({ selector: 'app-root', standalone: true, template: `{{ fullName() }}` }) export class AppComponent { firstName = signal('John'); lastName = signal('Smith'); fullName = computed(() => `${this.firstName()} ${this.lastName()}`); constructor() { this.lastName.set('Brown'); } }
Attempts:
2 left
💡 Hint
Signals update reactively, so computed signals reflect the latest values.
✗ Incorrect
The lastName signal is updated to 'Brown' in the constructor. The computed fullName reflects this change and returns 'John Brown'.
📝 Syntax
advanced2:00remaining
Which option correctly defines a computed signal for the sum of two signals?
You want to create a computed signal that returns the sum of two number signals: countA and countB. Which code snippet is correct?
Attempts:
2 left
💡 Hint
Remember to call signals as functions to get their current values.
✗ Incorrect
Signals are functions. To get their values inside computed, you must call them with (). Option C correctly calls both signals.
🔧 Debug
advanced2:00remaining
Why does this computed signal not update when signals change?
Look at this Angular component code. Why does fullName not update when firstName or lastName change?
Angular
import { Component, computed, signal } from '@angular/core'; @Component({ selector: 'app-root', standalone: true, template: `{{ fullName() }}` }) export class AppComponent { firstName = signal('Alice'); lastName = signal('Wonderland'); fullName = computed(() => this.firstName + ' ' + this.lastName); constructor() { this.firstName.set('Bob'); } }
Attempts:
2 left
💡 Hint
Check how signals are accessed inside the computed function.
✗ Incorrect
Signals must be called as functions to track dependencies. Using this.firstName without () returns the signal object, not its value, so computed does not update.
🧠 Conceptual
expert2:00remaining
What happens if a computed signal depends on another computed signal that throws an error?
In Angular signals, if computed signal A depends on computed signal B, and B throws an error during evaluation, what is the behavior of A when accessed?
Attempts:
2 left
💡 Hint
Think about how errors propagate in reactive computed chains.
✗ Incorrect
If a computed signal throws an error, any computed signal depending on it will also throw that error when accessed, propagating the failure.