# Reactivity How the runtime decides what to update when data changes, and the `$` handle for inspecting a live template from the browser console. Reactivity in templates follows the normal JavaScript distinction between reference and value semantics: - Objects and arrays pass by reference. Mutating properties or array entries inside an event handler propagates back to the template. - Primitives pass by value. A handler cannot mutate the caller's variable directly. Use one of the two patterns below to update a primitive attribute from a handler. **(a) Return-value.** Handler returns the new value, template assigns it. Sync, pure transforms. ```ts function trim(value: string): string { return value.trim(); } ``` ```html name = trim(name)}> ``` **(b) Callback.** Handler invokes a setter. Async, conditional, or updates more than one attribute. ```ts function onSubmit(form: Form, resetUI: () => void) { resetUI(); saveUser(form); } ``` ```html