Computed & Watchers Questions with Answers

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

Sample questions

Question 1Easy

Which function stops a watcher?

  1. watch.stop(id)
  2. cancelWatch()
  3. The function returned by watch()
  4. unwatch.all()

Answer: C. The function returned by watch()

Explanation

const stop = watch(...) then call stop() to dispose.

Step-by-step solution

  1. Store the return value.
  2. Call it to stop.

Why the other options are wrong

  • A. watch.stop(id) is not a Vue API for this; the correct choice is The function returned by watch().
  • B. cancelWatch() is not a Vue API for this; the correct choice is The function returned by watch().
  • D. unwatch.all() is not a Vue API for this; the correct choice is The function returned by watch().

Question 2Easy

Which should you use to show fullName from first and last refs?

  1. A watch that sets fullName
  2. A method called in onMounted
  3. A computed property
  4. A lifecycle hook

Answer: C. A computed property

Explanation

Pure derived data is the ideal use for computed.

Step-by-step solution

  1. Derive from sources.
  2. Template reads computed.

Why the other options are wrong

  • A. Works but is verbose and error prone.
  • B. It would not stay updated.
  • D. Hooks do not react to changes.

Question 3Easy

Which option makes watch run its callback immediately on creation?

  1. { immediate: true }
  2. { eager: true }
  3. { now: true }
  4. { onInit: true }

Answer: A. { immediate: true }

Explanation

immediate: true runs the callback once with the initial value.

Step-by-step solution

  1. Pass options as third argument.
  2. Set immediate.

Why the other options are wrong

  • B. { eager: true } is not a valid option here; the correct choice is { immediate: true }.
  • C. { now: true } is not a valid option here; the correct choice is { immediate: true }.
  • D. { onInit: true } is not a valid option here; the correct choice is { immediate: true }.

Question 4Easy

Which flush option runs a watcher after the DOM updates?

  1. flush: 'after'
  2. flush: 'post'
  3. flush: 'late'
  4. flush: 'dom'

Answer: B. flush: 'post'

Explanation

Values are 'pre' (default), 'post' and 'sync'.

Step-by-step solution

  1. Set flush post.
  2. Callback sees updated DOM.

Why the other options are wrong

  • A. 'after' is not a valid flush value; the values are pre, post and sync.
  • C. 'late' is not a valid flush value; the values are pre, post and sync.
  • D. 'dom' is not a valid flush value; the values are pre, post and sync.

Question 5Medium

In watch(source, cb), what are the first two arguments passed to cb?

  1. The old value and the new value
  2. The event and the component
  3. The new value and the old value
  4. The key and the value

Answer: C. The new value and the old value

Explanation

The callback signature is (newValue, oldValue).

Step-by-step solution

  1. A watch callback receives the new value first.
  2. The old value is the second argument.
  3. So the callback signature is new value, then old value (option C).

Why the other options are wrong

  • A. The order is the reverse: new value first, then old value.
  • B. An event and a component are not passed to a watch callback.
  • D. A key and value pair is not passed to a watch callback.

Tip: The watch callback signature is (newValue, oldValue).

Question 6Medium

Which is bad practice inside a computed getter?

  1. Reading refs and returning a value derived from them, as getters normally do
  2. Mutating other reactive state or calling an API
  3. Returning a filtered array
  4. Using a ternary

Answer: B. Mutating other reactive state or calling an API

Explanation

Computed getters should be pure derivations. Side effects belong in watchers or event handlers.

Step-by-step solution

  1. Getter must be side-effect free.
  2. Use watch for effects.

Why the other options are wrong

  • A. Reading is the purpose.
  • C. Derivation is expected.
  • D. Pure expressions are fine.

Question 7Medium

What does watchEffect track?

  1. Only values passed explicitly as an argument list, similar to the source of watch
  2. Nothing; it runs once
  3. Only refs, not reactive objects
  4. Every reactive value read synchronously inside the callback

Answer: D. Every reactive value read synchronously inside the callback

Explanation

watchEffect runs immediately and auto-tracks dependencies it touches synchronously.

Step-by-step solution

  1. It runs once at start.
  2. Dependencies read are recorded.

Why the other options are wrong

  • A. It has no source argument.
  • B. It re-runs when dependencies change.
  • C. Both are tracked.

Tip: Values read after an await are not tracked.

Question 8Medium

What is the difference between watch and watchEffect?

  1. watch runs immediately and watchEffect never runs initially
  2. watchEffect runs at once and auto-tracks; watch uses explicit sources
  3. They behave identically in every case
  4. watchEffect can only observe props, not local state

Answer: B. watchEffect runs at once and auto-tracks; watch uses explicit sources

Explanation

watchEffect auto-collects dependencies used inside; watch needs explicit sources and is lazy by default.

Step-by-step solution

  1. WatchEffect runs once straight away and tracks every reactive value it reads.
  2. Watch takes explicit sources and is lazy by default, so it does not run at first.
  3. So the difference is auto-tracking in watchEffect versus explicit sources in watch (option B).

Why the other options are wrong

  • A. Watch is lazy by default, and watchEffect does run initially.
  • C. They differ in how dependencies are collected and in the initial run.
  • D. WatchEffect can observe any reactive state it reads, not only props.

Tip: Use watch when you need the old value or explicit sources; use watchEffect for simple auto-tracking.

Question 9Hard

Why does watch(state, cb) with a reactive state fire on nested changes?

  1. Because the callback was registered with the immediate option so it re-runs on children
  2. Watching a reactive object is implicitly deep
  3. Because state is a ref
  4. Because of flush post

Answer: B. Watching a reactive object is implicitly deep

Explanation

A reactive object as source is deep by default; a ref holding an object needs deep: true.

Step-by-step solution

  1. Source is reactive.
  2. Deep traversal is implied.

Why the other options are wrong

  • A. Immediate is unrelated.
  • C. It is not a ref.
  • D. Flush controls timing, not depth.

Question 10Hard

What does this watcher do on a reactive object state?

watch(() => state.user.name, (n, o) => {})
  1. Fires on any change anywhere in state, including properties of other objects
  2. Never fires
  3. Fires once and stops
  4. Fires only when state.user.name changes

Answer: D. Fires only when state.user.name changes

Explanation

A getter source tracks exactly the reactive values it reads.

Step-by-step solution

  1. Getter reads state.user.name.
  2. Only that dependency triggers.

Why the other options are wrong

  • A. Only the getter's dependencies are tracked.
  • B. The getter makes it track name.
  • C. It keeps running.

Practise all 22 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