Vue · Junior · Question 75 of 75

Why can a ref declared with const still change?

const count = ref(0)
count.value++ // works

Explanation

Writing count = ref(1) would fail and also break every place that holds the old ref. Use readonly() to make a value truly read-only.

Further reading

Problem with a question

Vue · Junior · question 75

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