The selected class is added to the element whenever the value of the expression is truthy, and removed when it's falsy.
xxxxxxxxxx
<button
class:selected="{current === 'foo'}"
on:click="{() => current = 'foo'}"
>foo</button>
xxxxxxxxxx
<button
class:selected="{current === 'foo'}"
on:click="{() => current = 'foo'}"
>foo</button>