HTML5 Interview Questions Part 4

16. What is Web SQL Database in HTML5?


Web SQL database is not a part of the HTML5 specification but it is a separate specification which introduces a set of APIs to manipulate client-side databases using SQL.

Following are the three methods of Web SQL database,

1. openDatabase
2. transaction
3. executeSql

With the help of openDatabase method, you can create an object for the database.

To create and open the database, you need to use the following syntax,

var dbObj = OpenDatabase('[Database_Name]', '[Version_Number]', '[Text_Description]', '[size]', '[Creation_Callback]')

A transaction method gives us the ability to control a transaction and performing either commit or rollback based on the situation.

The executeSql method is used to execute actual SQL query.

17. Why should we use IndexedDB?


IndexedDB is an API that allows a user to store large amount of data in the browser and it is more powerful and efficient than Web SQL.

Most of the browsers like Mozilla do not support Web SQL. The use of Web SQL is obsolete and deprecated and not recommended to use in your application, so this is also a limitation of Web SQL.

IndexedDB stores the data as Key-Pair values and can access the data from the same domain.

It is mostly asynchronous and is not a structured query language.

18. What is Modernizr in HTML5?


Modernizr is an open source JavaScript library which helps to detect the availability of native implementations for next-generation web technologies.

It is designed to detect HTML5 and CSS3 features in various browsers. Its main purpose is to provide this feature detection in a complete and standardized manner, so that you can take corresponding action. For example, if a browser does not support video feature then you would like to display a simple page.

You have to include Modernizr javascript library in your HTML page before you start using Modernizr, shown as below,

<script src="modernizr.min.js" type="text/javascript"></script>

19. What is the purpose of Language attribute in HTML5?


Language attribute is important for accessibility applications (screen readers) and search engines.

The language is declared in Language attribute and the document language can be declared in the <HTML> tag.

<html lang="en-US">

20. What is WebSocket API?


WebSocket is a rich communication protocol that provides full-duplex communication channels over a single TCP connection.

It makes interactive communication session between the user's browser and a server.

Using WebSocket API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.