#ActuallyAutistic web dev. Does front of the front-end. Loves perf and minimalism. Prefers HTML, CSS, Web Standards over JS, UX over DX. Hates div disease.
And here is the shortest code to check to see if you can actually use the localStorage:
// usage: put return value to a variable or use as a if condition!function(l){try{(l=localStorage).removeItem(l._='_')}catch(e){return1}}()
You could also write a wrapper that would take care of cases like running out of localStorage space, but that is quite an overkill for most use cases. In the other hand if you do have lots of localStorage usage and/or need the abstraction (for code readability/maintenance reasons) then it will probably be worth it over a simple boolean check like the above.
And here is the shortest code to check to see if you can actually use the localStorage:
You could also write a wrapper that would take care of cases like running out of localStorage space, but that is quite an overkill for most use cases. In the other hand if you do have lots of localStorage usage and/or need the abstraction (for code readability/maintenance reasons) then it will probably be worth it over a simple boolean check like the above.
Very nice quick check! Love it <3