HTML5 Interview Questions Part 2

6. What are the types of Web Workers in HTML5?

Answer:

Using web workers you can achieve multi threading in your web applications.

There are two types of Web Workers,
1. Dedicated Workers
2. Shared Workers

1. Dedicated Workers

Dedicated worker is accessible from the parent script that created it. Dedicated Workers is supported by all browsers.

2. Shared Workers

A shared worker can be accessed from any script of the same origin.
It can work with multiple connections.
It is supported by limited browsers like Chrome 4.0+, Safari 5.0+ and Opera 10.6+.

7. What are the limitations of Web Workers?

Answer:

Web workers cannot access DOM elements.

It cannot access window object, document object and parent object.

You cannot load images and cannot create canvas elements and draw to them from web workers.

8. What is Web Storage?

Answer:

Web storage is a way to preserve state in either the client or server which makes it much easier to work against the stateless nature of HTTP.

It is also known as DOM storage.

Web storage stores 5 to 10 MB data which is far more than what cookies have.

It increases the performance of the application because the web storage data is never transferred with HTTP request.

9. What are the web storage methods in HTML5?

Answer:

Following are the web storage methods,

setItem(key,value): It adds a key/value pair to the sessionStorage object.

getItem(key): It retrieves the value for a given key.

clear(): It removes all key/value pairs for the sessionStorage object.

removeItem(key): It removes a key/value pair from the sessionStorage object.

key(n): It retrieves the value for a key.

10. What are the types of Web Storage?

Answer:

There are two types of Web Storage,
   1. Session Storage
   2. Local Storage

1. Session Storage

Session storage stores data of current session which means that the data stored in a session storage clears when the browser is closed.

To store data in session storage, setItem () function is used.

Syntax:
sessionStorage.setItem ('key','value');   

Example:
sessionStorage.setItem ('user-name','PQR');

2. Local Storage

Local storage stores data in KEY/VALUE pair of strings.

The data stored in local storage is not deleted automatically when the current browser window is closed, it clears only when it is manually deleted.

To store data in Local Storage, setItem() function is used.

Syntax:
localStorage.setItem ('key','value');

Example:
localStorage.setItem ('username','ABC');