0
Hours
0
Minutes
0
Seconds
You need Login/Signup to run/submit the code.

Design and Implement localStorage API | Frontend Problem Solving | JavaScript Interview Question

@Devtools Tech
1644

In this question, you need to design and implement the localStorage API. It should mimic the behaviour of existing window.localStorage.

Properties

  1. localStorage.length

Returns an integer representing the number of data items stored in the localStorage object.

Methods:

  1. localStorage.setItem(key, value)

When passed a key name and value, will add that key to the storage, or update that key's value if it already exists.

  1. localStorage.getItem(key)

When passed a key name, will return that key's value.

  1. localStorage.removeItem(key)

When passed a key name, will remove that key from the storage.

  1. localStorage.clear()

When invoked, will empty all keys out of the storage.

Make sure you handle different edge cases

Submission

Start the timer and try to complete the solution within 30 mins. You can share your solution on social media and tag us @devtoolstech.

Loading IDE...