Workshop › Snake › Step 26 of 28
The best score should survive closing the page. localStorage keeps small pieces of text in the browser.
```js
let best = Number(localStorage.getItem('snake-best')) || 0
if (score > best) {
best = score
localStorage.setItem('snake-best', best)
}
ctx.fillText('Best: ' + best, 8, 40)
```localStorage.getItem('snake-best') reads the saved text (or null the first time); Number(...) turns it
into a number, and || 0 falls back to 0.best and save it with setItem.let gameOver write the best line.update, under gameOver = true, write the if (score > best) block.draw, under the Score line, write the Best line.Skills: Game states
← Play again with Space Speed up as you grow →