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}`);

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.

Further reading

Problem with a question

Vue · Junior · question 16

Test yourself

Take the Vue · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz