Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any difference between: window.localStorage and localStorage?

People also ask

What is window localStorage?

localStorage. The localStorage read-only property of the window interface allows you to access a Storage object for the Document 's origin; the stored data is saved across browser sessions.

Is localStorage shared between Windows?

The main features of localStorage are: Shared between all tabs and windows from the same origin. The data does not expire. It remains after the browser restart and even OS reboot.

How long does window localStorage last?

LocalStorage has no expiration time, Data in the LocalStorage persist till the user manually delete it.


Unless you've declared a variable named localStorage in a custom defined scope, they're the same. localStorage refers to window.localStorage. In fact every variable in global namespace can be accessed as window.<variableName>

For example:

<script>
function foo() {
    // here window.localStorage == localStorage
}
function foo2() {
    var localStorage = 10;
    // here window.localStorage != localStorage 
    // since you have a local variable named localStorage
}
</script>

"window" is the global object in Javascript, so you can ommit it if there's no chance for a conflict


there is no difference between the window.localStorage and localStorage the Window is the global object

the window is the default prefix

but the correct one is window.localStorage because the localStorage attribute is part of window object.


This is old, but today I may have found a difference.

I have a React app that was 'forgetting' the localstorage values when I ran it on my server with SSL without the WI DOW . Without SSL, it was working fine.

I went back and added the WINDOW to all the references to localstorage and the problem disappeared