Reactivity Questions with Answers

21 practice questions on Reactivity (Vue.js) with answers and step-by-step solutions. Try 10 samples below, then practise all 21 free in the AptiNest app.

Sample questions

Question 1Easy

What does a ref return when you create it with ref(0)?

  1. An object with a .value property holding 0
  2. The number 0 itself, copied into a plain variable that Vue watches
  3. A plain array [0]
  4. A function that returns 0

Answer: A. An object with a .value property holding 0

Explanation

ref() wraps the value in a reactive object whose .value you read and write in script code.

Step-by-step solution

  1. Call ref(0).
  2. Vue wraps 0 in an object.
  3. Access it with .value in script.

Why the other options are wrong

  • B. A ref wraps the value in an object.
  • C. An array is not used.
  • D. It is an object, not a function.

Tip: Templates unwrap refs automatically; scripts do not.

Question 2Easy

Which function makes an object deeply reactive in Vue 3?

  1. reactive()
  2. ref.object()
  3. observe()
  4. Vue.set()

Answer: A. reactive()

Explanation

reactive(obj) returns a Proxy that tracks nested property access.

Step-by-step solution

  1. Pass a plain object.
  2. Get back a Proxy.
  3. Reads and writes are tracked.

Why the other options are wrong

  • B. No such function exists.
  • C. observe is a Vue 2 internals term, not an API.
  • D. Vue.set was for Vue 2 and is not needed.

Question 3Easy

Why is {{ count }} in the template not written as {{ count.value }}?

  1. It is a typo, since templates need .value just like script code does
  2. Vue runs eval
  3. Top-level refs are automatically unwrapped in templates
  4. Refs are numbers

Answer: C. Top-level refs are automatically unwrapped in templates

Explanation

Templates unwrap top-level refs; nested refs inside plain objects are not unwrapped.

Step-by-step solution

  1. ref is returned to template.
  2. Template unwraps it.

Why the other options are wrong

  • A. It is correct.
  • B. Not eval.
  • D. They are objects.

Question 4Easy

Which API makes a reactive object read-only for consumers?

  1. freeze()
  2. lock()
  3. const
  4. readonly()

Answer: D. readonly()

Explanation

readonly(obj) returns a proxy that warns on writes in development.

Step-by-step solution

  1. Pass the object to readonly.
  2. Writes are rejected with a warning.

Why the other options are wrong

  • A. Not a Vue API (Object.freeze is plain JS).
  • B. Not a Vue API.
  • C. const only blocks reassignment of the variable.

Question 5Medium

What is triggerRef(r) used for?

  1. Creating a new ref that wraps a deep clone of the original value as a copy
  2. Forcing dependents of a shallowRef to update after an in-place mutation
  3. Resetting r to null
  4. Cancelling a watcher

Answer: B. Forcing dependents of a shallowRef to update after an in-place mutation

Explanation

It manually notifies subscribers when internals are changed without replacing .value.

Step-by-step solution

  1. Mutate in place.
  2. Call triggerRef.

Why the other options are wrong

  • A. It does not create.
  • C. It does not reset.
  • D. It does not cancel.

Question 6Medium

What does markRaw(obj) do?

  1. Makes the object deeply reactive so that every nested property is tracked automatically
  2. Prevents the object from ever being turned into a reactive proxy
  3. Freezes the object with Object.freeze
  4. Creates a read-only copy

Answer: B. Prevents the object from ever being turned into a reactive proxy

Explanation

markRaw flags an object so Vue will not proxy it, useful for large third-party instances such as maps or charts.

Step-by-step solution

  1. Wrap the object in markRaw.
  2. Vue sets a skip flag.
  3. Later ref/reactive leaves it unproxied.

Why the other options are wrong

  • A. That is the opposite.
  • C. It sets a skip flag, not freeze.
  • D. readonly() does that.

Question 7Medium

Given the code below, what is shown after inc() is called twice?

const n = ref(1)
function inc(){ n.value++ }

(template: {{ n }})

  1. 1
  2. 3
  3. 2
  4. [object Object]

Answer: B. 3

Explanation

Each n.value++ mutates the ref; the template shows the unwrapped value 1+2 = 3.

Step-by-step solution

  1. Start at 1.
  2. First call makes it 2.
  3. Second call makes it 3.

Why the other options are wrong

  • A. Both increments update the ref.
  • C. Only the first call would give 2.
  • D. Templates unwrap the ref to a number.

Question 8Medium

Which utility converts each property of a reactive object into a ref that stays linked to the source?

  1. toRefs()
  2. toRaw()
  3. markRaw()
  4. unref()

Answer: A. toRefs()

Explanation

toRefs() creates refs linked to the original properties, so destructuring keeps reactivity.

Step-by-step solution

  1. toRefs() takes a reactive object.
  2. It returns an object where each property is a ref linked to the original property.
  3. So destructuring the result keeps the values reactive.
  4. The answer is toRefs() (option A).

Why the other options are wrong

  • B. toRaw() returns the plain object without reactivity.
  • C. markRaw() stops an object from being made reactive.
  • D. unref() reads the value out of a ref; it does not create refs.

Tip: toRefs() is the tool for destructuring reactive objects without losing reactivity.

Question 9Hard

Which triggers reactivity in Vue 3 for a reactive array arr?

  1. arr[0] = 5 (index assignment)
  2. None of these; Vue 3 cannot detect writes by index, so use splice only
  3. Only arr.splice
  4. Only Vue.set(arr,0,5)

Answer: A. arr[0] = 5 (index assignment)

Explanation

Proxies track index writes, unlike Vue 2.

Step-by-step solution

  1. Vue 3 uses Proxy.
  2. Index set is trapped.

Why the other options are wrong

  • B. Proxy detects it.
  • C. Both work.
  • D. Vue.set is removed.

Question 10Hard

Given const list = ref([1,2,3]), which statement triggers a re-render in Vue 3?

  1. list.push(4), because refs proxy array methods directly
  2. list.value.push(4)
  3. list = [1, 2, 3, 4], reassigning the variable
  4. list.length = 4, changing the ref's length

Answer: B. list.value.push(4)

Explanation

Mutating the array through .value is tracked; list.push fails since a ref is not an array, and reassigning a const throws.

Step-by-step solution

  1. List is a ref, so the array lives at list.value.
  2. list.value.push(4) changes that array through the ref.
  3. Vue tracks the change through .value and re-renders.
  4. So list.value.push(4) triggers a re-render (option B).

Why the other options are wrong

  • A. A ref does not proxy array methods, so list.push is undefined.
  • C. Const cannot be reassigned, so this throws and does not update the array.
  • D. A ref has no length to change, so this does not update the array.

Tip: Read or mutate a ref's contents through .value in script code.

Practise all 21 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Vue.js topics · All topics