Sample questions
Question 1Easy
Which function stops a watcher?
- watch.stop(id)
- cancelWatch()
- The function returned by watch()
- unwatch.all()
Answer: C. The function returned by watch()
Explanation
const stop = watch(...) then call stop() to dispose.
Step-by-step solution
- Store the return value.
- 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?
- A watch that sets fullName
- A method called in onMounted
- A computed property
- A lifecycle hook
Answer: C. A computed property
Explanation
Pure derived data is the ideal use for computed.
Step-by-step solution
- Derive from sources.
- 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?
- { immediate: true }
- { eager: true }
- { now: true }
- { onInit: true }
Answer: A. { immediate: true }
Explanation
immediate: true runs the callback once with the initial value.
Step-by-step solution
- Pass options as third argument.
- 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?
- flush: 'after'
- flush: 'post'
- flush: 'late'
- flush: 'dom'
Answer: B. flush: 'post'
Explanation
Values are 'pre' (default), 'post' and 'sync'.
Step-by-step solution
- Set flush post.
- 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?
- The old value and the new value
- The event and the component
- The new value and the old value
- 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
- A watch callback receives the new value first.
- The old value is the second argument.
- 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?
- Reading refs and returning a value derived from them, as getters normally do
- Mutating other reactive state or calling an API
- Returning a filtered array
- 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
- Getter must be side-effect free.
- 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?
- Only values passed explicitly as an argument list, similar to the source of watch
- Nothing; it runs once
- Only refs, not reactive objects
- 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
- It runs once at start.
- 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?
watch runs immediately and watchEffect never runs initiallywatchEffect runs at once and auto-tracks; watch uses explicit sources- They behave identically in every case
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
- WatchEffect runs once straight away and tracks every reactive value it reads.
- Watch takes explicit sources and is lazy by default, so it does not run at first.
- 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?
- Because the callback was registered with the immediate option so it re-runs on children
- Watching a reactive object is implicitly deep
- Because state is a ref
- 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
- Source is reactive.
- 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) => {})
- Fires on any change anywhere in state, including properties of other objects
- Never fires
- Fires once and stops
- 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
- Getter reads state.user.name.
- 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 →