سؤال

Is there any difference between:

localStorage.setItem('foo', 1);

and:

localStorage.setItem('foo', true);

From the point of view of storage requirements? Is there any kind of value optimization carried out by the browser before actually storing data (i.e. compression)?

Please note that I'm assuming that Local Storage can handle any type of data and not just strings. I'm not sure about this.

هل كانت مفيدة؟

المحلول

Any non-strings that you store in localStorage are converted to strings before being stored. So true would be stored as "true", and 1 would be stored as "1".

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top