Web Storage


Short Quiz

1. Name six of the storage API methods.

According to http://www.w3.org/TR/webstorage/ length is an attribute and the methods are key(n), getItem(key), setItem(key, value), removeItem(key), and clear().

2. What do you use to create/set data, retrieve data or remove it from a cache?

There are two ways to set, get, or delete data. One way is as follow:

  • sessionStorage.setItem('twitter', '@Luis');
  • sessionStorage.getItem('twitter');
  • sessionStorage.removeItem('twitter');

The second method is called "expando"

  • sessionStorage.twitter = '@Luis';
  • sessionStorage.twitter;
  • delete sessionStorage.twitter;

Where JavaScript makes the setItem, getItem, and removeItem call for us.

3. Write the two lines required to remove a data cache.

According to one of the articles on html5doctor.com and our lecture. The following methods should remove all data.

  • delete localStorage.facebook;
  • console.log(localStorage.facebook);

But I find that using only:

  • delete localStorage.facebook;

does the job without calling the other statement at least in Firefox.

4. What is the downside to web storage?

The downside is that the data is stored as strings only. Math operations are not possible. A work around is the used of JSON to create objects. Once the object(s) are created then they can be manipulated depending the applicacion.

5. Does the event fire on the same window that stored the cache?

No, the event only fires on windows other than the one that stored the data like iframes or popups generated from the same page.

Published by Luis

Comments

Very cool!

Validation and Outline


Validation

Please check my validation here.

Published by HTML5.validator.nu

Outline

Please check my outline here. It is a very nice outline except for the Menu section but that is no big deal.

Published by HTML5.org