AI Workshop: learn to build apps with AI →
Storage: Setting an item

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


setItem() adds an item to the storage. It accepts two arguments: the key (a string) and the value (a string).

localStorage.setItem('username', 'flaviocopes')
localStorage.setItem('id', '123')

If you pass a value that is not a string, it is converted to a string:

localStorage.setItem('test', 123) // stored as the string '123'
localStorage.setItem('test', { test: 1 }) // stored as "[object Object]"

Lessons in this unit:

0: Introduction
1: Session vs local storage
2: ▶︎ Setting an item
3: Getting an item value
4: Removing an item
5: Clearing storage
6: Storage size limits