Vue · Junior · Question 16 of 75
What is computed() for?
const firstName = ref("Ann");
const lastName = ref("Lee");
const fullName = computed(() => `${firstName.value} ${lastName.value}`);- ✓Correct answer: A derived value that is cached and recalculated only when its reactive dependencies change
- 2A function that runs on every render regardless of dependencies
- 3A watcher that performs side effects
Explanation
A method called in the template runs on every re-render; a computed property returns the cached result until firstName or lastName changes. Computed getters should be free of side effects.