Working through the official svelte example of writable-stores https://learn.svelte.dev/tutorial/writable-stores
Wondering why this works in updating count
function increment() {
count.update((n) => n+1);
}
and this does not?
function increment() {
count.update((n) => n++);
}
>Solution :
n++ is a post-increment operator. It returns the current value, then increments the variable. In this case, you want to use the pre-increment operator, which looks like ++n. It first increments the value, then returns the already incremented value.
function increment() {
count.update((n) => ++n);
}