0 day streak
javascript / beginner
Snippet

Two-Way Data Binding

Data binding synchronizes the value of a variable with a form input. When the user types, the variable updates, and when the variable changes, the input updates.

snippet.js
javascript
1
2
3
4
5
6
7
<script>
let name = 'Svelte';
</script>
<input bind:value={name} />
<p>Hello, {name}!</p>
svelte
Breakdown
1
bind:value={name}
Creates a two-way link between the input value and the 'name' variable.
2
{name}
Displays the current value of the 'name' variable in the paragraph.