0
0
Angularframework~20 mins

Computed signals for derived values in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Computed Signals Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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()}`);
}
AError: fullName is not a function
BJane Doe
CDoe
DJane
Attempts:
2 left
💡 Hint
Remember that computed signals are functions that return the derived value.
state_output
intermediate
2: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');
  }
}
AJohn Brown
BJohn Smith
CBrown
DJohn
Attempts:
2 left
💡 Hint
Signals update reactively, so computed signals reflect the latest values.
📝 Syntax
advanced
2: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?
Asum = computed(() => countA() + countB);
Bsum = computed(() => countA + countB);
Csum = computed(() => this.countA() + this.countB());
Dsum = computed(() => this.countA + this.countB());
Attempts:
2 left
💡 Hint
Remember to call signals as functions to get their current values.
🔧 Debug
advanced
2: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');
  }
}
ABecause fullName is missing a return statement.
BBecause signals cannot be used inside computed signals.
CBecause the constructor updates firstName before fullName is defined.
DBecause signals are not called as functions inside computed, so dependencies are not tracked.
Attempts:
2 left
💡 Hint
Check how signals are accessed inside the computed function.
🧠 Conceptual
expert
2: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?
AAccessing A will also throw the same error because it depends on B.
BA will return undefined silently without throwing an error.
CA will cache the last successful value and not throw an error.
DA will ignore B's error and return a default value.
Attempts:
2 left
💡 Hint
Think about how errors propagate in reactive computed chains.