Assigning state.count = 5 updates the reactive property value.
Step 2: Check the logged value
Logging state.count after update outputs the new value 5.
Final Answer:
5 -> Option A
Quick Check:
Updated reactive property logs new value = D [OK]
Hint: Reactive objects update properties directly and reflect changes [OK]
Common Mistakes:
Thinking reactive objects are immutable
Expecting old value after update
Confusing reactive with ref syntax
4. What is wrong with this Vue 3 code snippet?
import { reactive } from 'vue'
const state = reactive({ count: 0 })
state = { count: 5 }
medium
A. You cannot reassign a reactive object variable directly.
B. The reactive function requires an array, not an object.
C. The property count must be declared with ref(), not reactive.
D. Reactive objects cannot have numeric properties.
Solution
Step 1: Identify the error in variable reassignment
The variable state is declared with const, so it cannot be reassigned.
Step 2: Understand reactive object usage
Reactive objects are mutable in their properties but the variable holding them cannot be reassigned if declared const.
Final Answer:
You cannot reassign a reactive object variable directly. -> Option A
Quick Check:
const variable reassignment causes error = A [OK]
Hint: const variables can't be reassigned, only their properties changed [OK]
Common Mistakes:
Trying to reassign const reactive variables
Confusing reactive() input types
Thinking reactive objects restrict property types
5. You want to create a reactive object to track a user's profile with nested address info. Which code correctly makes the entire object reactive so changes to nested properties update the UI?