Friday, August 26, 2016

HTML5 Questions and Answers 2016

1. Which of the following statements regarding WebSockets is true?
Answers:
  1. It communicates with the server with only the data required by the application.
  2. It lowers the latency of connections for interactive web applications.
  3. It scales better and consumes less server resources than HTTP AJAX/long-poll.
  4. All of the above.
2. Assuming that some text needs to be written on an HTML5 canvas, select a replacement for the commented line below:
<canvas id=”e” width=”200″ height=”200″></canvas>
<script>
var canvas = document.getElementById(“e”);
//insert code here
context.fillStyle = “blue”;
context.font = “bold 16px Arial”;
context.fillText(“Zibri”, 100, 100);
</script>
Answers:
  1. var context = canvas.getContext();
  2. var context = canvas.getElementById(“context”);
  3. var context = canvas.getContext(“2d”);
  4. var context = canvas.getElementById(“2d”);
3. What is the role of the <dfn> element in HTML5?
Answers:
  1. It is used to define important text.
  2. It is used to define computer code text.
  3. It is used to define sample computer code.
  4. It is used to define a definition term.
4. Which of the following is a possible way to get fullscreen video played from the browser using HTML5?
Answers:
  1. <object> <param name=”allowFullScreen” value=”true” />
  2. <video allowFullScreen=”true”>
  3. <video height=”100%” width=”100%”>
  4. None of these.
5. Consider the following items of a <select> list:
<option value=”89″>Item 1</option>
<option value=”90″>Item 2</option>
Which of the following values would be passed on by clicking the submit button on selecting Item 2 from the list?
Answers:
  1. 89
  2. 90
  3. Item 1
  4. Item 2
6. The following are valid use cases of client file/directory access in HTML5, except:
Answers:
  1. Drag and drop files from the desktop
  2. Full file system access
  3. Use of the HTML5 File API
  4. Use of files as HTML5 input types
7. Which of the following are the valid values of the <a> element’s target attribute in HTML5?
Answers:
  1. _blank
  2. _self
  3. _top
  4. _bottom
8. How does a button created by the <button> tag differ from the one created by an <input> tag?
Answers:
  1. An input tag button can be a reset button too.
  2. A button tag button can be a reset button too.
  3. An input tag button can include images as well.
  4. A button tag can include images as well.
9. Which method of HTMLCanvasElement is used to represent image of Canvas Element?
Answers:
  1. toDataURL()
  2. saveAsImage()
  3. saveFile()
  4. exportImage()
10. Can we store JavaScript Objects directly into localStorage?
Answers:
  1. Yes
  2. No
11. When does the ondragleave mouse event get fired in HTML5?
Answers:
  1. It gets fired when an element has been dragged to a valid drop target.
  2. It gets fired when an element leaves a valid drop target.
  3. It gets fired at the end of a drag operation.
  4. It gets fired while an element is being dragged.
12. Once an application is offline, it remains cached until the following happens (select all that apply):
Answers:
  1. The application cache is programmatically updated.
  2. The application cache gets automatically cleared by the browser.
  3. The manifest file is modified.
  4. The user clears their browser’s data storage for the site.
13. What is the internal/wire format of input type=”date” in HTML5?
Answers:
  1. DD-MM-YYYY
  2. YYYY-MM-DD
  3. MM-DD-YYYY
  4. YYYY-DD-MM
14. Which of the following is not a valid syntax for the <link> element in HTML5?
Answers:
  1. <link rel=”icon” href=”abc.jpg” sizes=”16×16″>
  2. <link rev=”stylesheet” href=”abc.css” type=”text/css” target=”_parent”>
  3. <link rel=”alternate” type=”application/pdf” hreflang=”fr” href=”manual-fr”>
15. What does P2P streaming mean when web applications establish a P2P HTTP connection using HTML?
Answers:
  1. It means that streaming of a voice/video frame is direct, without using any server between them.
  2. It means that streaming of a voice/video frame is first between one peer to the server then the server to another peer.
  3. Communication does not rely on a shared relay server in the network.
16. Which of the following will detect when an HTML5 video has finished playing?
Answers:
  1. var video = document.getElementsByTagName(‘video’)[0]; video.onended = function(e) { }
  2. var video = document.getElementsByTagName(‘video’)[0]; video.onPlayend = function(e) { }
  3. var video = document.getElementsByTagName(‘video’)[0]; video.onPlayFinish = function(e) { }
  4. var video = document.getElementsByTagName(‘video’)[0]; video.onPlayBackended = function(e) { }
17. What is the difference between Server-Sent Events (SSEs) and WebSockets in HTML5?
Answers:
  1. WebSockets can perform bi-directional (client-server and vice versa) data transfers, while SSEs can only push data to the client/browser.
  2. SSEs can perform bi-directional (client-server and vice versa) data transfers, while WebSockets can only push data to the client/browser.
  3. WebSockets and SSEs are functionally equivalent.
  4. None of these.
18. Which of the following methods can be used to estimate page load times?
Answers:
  1. Using _gaq.push([‘_trackPageLoadTime’]) with Google Analytics.
  2. Using the Navigation Timing JavaScript API.
  3. Page load times cannot be estimated.
  4. Using built-in JavaScript methods.
19. Which of the following are valid ways to associate custom data with an HTML5 element?
Answers:
  1. <tr class=”foo” data-id-type=”4″>
  2. <tr class=”foo” id-type=”4″>
  3. <tr class=”foo” data-id_type=”4″>
  4. All of the above.
20. How can an HTML5 canvas size be changed so that it fits the entire window?
Answers:
  1. #myCanvas {height: 100%; width: 100%;}
  2. <script type=”text/javascript”> function resize_canvas(){ canvas = document.getElementById(“canvas”); if (canvas.width < window.innerWidth) { canvas.width = window.innerWidth; } if (canvas.height < window.innerHeight) { canvas.height = window.innerHeight; } } </script>
  3. It depends upon the complexity of the canvas, and the frequency of redraws.
  4. Calling the JavaScript getWidth() function.
21. Which method of the HTMLCanvasElement is used to represent an image of a canvas element?
Answers:
  1. toDataURL
  2. toImageURL
  3. saveAsPNG
  4. saveAsJPEG
22. Which of the following is the correct way to store an object in localStorage?var obj = { ‘one’: 1, ‘two’: 2, ‘three’: 3 };
Answers:
  1. localStorage.setItem(‘obj’, obj);
  2. localStorage.setItem(‘obj’, JSON.stringify(obj));
  3. localStorage.setItem(‘testObject’, JSON.parse(testObject));
  4. localStorage.setItem(obj);
23. Assuming that some text needs to be written on an HTML5 canvas, select a replacement for the commented line below:
<canvas id=”e” width=”200″ height=”200″></canvas>
<script>
var canvas = document.getElementById(“e”);
//insert code here
context.fillStyle = “blue”;
context.font = “bold 16px Arial”;
context.fillText(“Zibri”, 100, 100);
</script>
Answers:
  1. var context = canvas.getContext();
  2. var context = canvas.getElementById(“context”);
  3. var context = canvas.getContext(“2d”);
  4. var context = canvas.getElementById(“2d”);
24. Which of the following code is used to prevent Webkit spin buttons from appearing on web pages?
Answers:
  1. input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; }
  2. input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
  3. noindex:-o-prefocus, input[type=number] { padding-right: 1.2em; }
  4. input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; padding-right: 1.2em; }
25. Which of the following will restrict an input element to accept only numerical values in a text field?
Answers:
  1. <input type=”text” pattern=”[0-9]*” />
  2. <input type=”number” />
  3. <input type=”text” pattern=”d*”/>
  4. <input type=”text” pattern=”number”/>
26. Which of the following is the correct way to display a PDF file in the browser?
Answers:
  1. <object type=”application/pdf” data=”filename.pdf” width=”100%” height=”100%”/>
  2. <object type=”application/pdf” id=”filename.pdf” width=”100%” height=”100%”/>
  3. <input type=”application/pdf” data=”filename.pdf” width=”100%” height=”100%”/>
  4. <input type=”application/pdf” src=”filename.pdf” width=”100%” height=”100%”/>
27. Which of the following is the best method to detect HTML5 Canvas support in web browsers?
Answers:
  1. isCanvasSupported()
  2. !!document.createElement(“canvas”)
  3. !isCanvasSupported()
  4. !!window.HTMLCanvasElement
28. Which media event is triggered when there is an error in fetching media data in HTML5?
Answers:
  1. onstalled
  2. onwaiting
  3. onsuspend
  4. oninvalid
29. Which of the following is the correct way to check browser support for WebSocket?
Answers:
  1. console.log(WebSocket ? ‘supported’ : ‘not supported’);
  2. console.log(window.WebSocket ? ‘supported’ : ‘not supported’);
  3. console.log(window[WebSocket] ? ‘supported’ : ‘not supported’);
  4. console.log(window[‘WebSocket’] ? ‘supported’ : ‘not supported’);
30. Which of the following video file formats are currently supported by the <video> element of HTML5?
Answers:
  1. CCTV
  2. MPEG 4
  3. Ogg
  4. 3GPP
31. Which of the following shows correct use of client-side data validation in HTML5, on username and password fields in particular?
Answers:
  1. <input name=”username” required /> <input name=”pass” type=”password” required/>
  2. <input name=”username” validate=”true”/> <input name=”pass” type=”password” validate=”true”/>
  3. <input name=”username” validate/> <input name=”pass” type=”password” validate/>
  4. There is no way to implement client-side validation for the username and password fields in HTML5.
32. Which of the following is not a valid attribute for the <video> element in HTML5?
Answers:
  1. controls
  2. autoplay
  3. disabled
  4. preload
33. Consider the following JavaScript code:
var c=document.getElementById(“myCanvas”);
var ctx=c.getContext(“2d”);
var img=document.getElementById(“img”);
Which method will correctly draw an image in the x=10, y=10 position?
Answers:
  1. ctx.drawImage(img,10,10);
  2. context.drawImage(img,20,10,10,10);
  3. context.drawImage(img,10,20,10,10,20,20,10,10);
  4. All of these
34. Which of the following is the correct way to store an object in a localStorage?
Answers:
  1. localStorage.setItem(‘testObject’, JSON.stringify(testObject))
  2. localStorage.setItem(‘testObject’, testObject)
  3. localStorage.add(‘testObject’, testObject)
  4. localStorage.addItem(‘testObject’, testObject)
35. How can audio files be played in HTML5?
var sound = new Audio(“file.wav”);
Answers:
  1. sound.begin();
  2. sound.resume();
  3. sound.start();
  4. sound.play();
36. Which of the following is the correct way to play an audio file in HTML5?
Answers:
  1. var snd = new Audio(“file.wav”); snd.play();
  2. <audio controls> <source src=”file.ogg” type=”audio/ogg”> <source src=”file.mp3″ type=”audio/mpeg”> </audio>
  3. <source src=”file.mp3″ type=”audio/mpeg”>
  4. All of these.
37. Which HTML5 doctype declarations are correct?
Answers:
  1. <!doctype html>
  2. <!DOCTYPE html>
  3. <!DOCTYPE HTML5>
  4. <!DOCTYPE HTML>
38. You want to create a link for your website allowing users to email the webmaster. How will you implement this if the webmaster’s email address is webmaster@xcompany.com?
Answers:
  1. <a href=”mailto:webmaster@xcompany.com”>webmaster</a>
  2. <a href=”webmaster@xcompany.com”>webmaster</a>
  3. <a http=”mail:webmaster@xcompany.com”>webmaster</a>
  4. <mail http=”send:webmaster@xcompany.com”>webmaster</mail>
39. Which of the following are sample use cases for HTML5 web workers?
Answers:
  1. Polling URLs in background
  2. Syntax highlighting without blocking code editing capabilities in online IDEs
  3. Motion tracking input in realtime with a video element
  4. All of these.
40. Which media event will be fired when a media resource element suddenly becomes empty?
Answers:
  1. onerror
  2. onended
  3. onloadeddata
  4. onemptied
41. You are writing the code for an HTML form and you want the browser to retain the form’s input values. That is, if a user submits the form and presses the browser’s back button, the fully populated form is displayed instead of a blank form. Which of the following HTML 5 attributes will you use?
Answers:
  1. accept
  2. autofocus
  3. autocomplete
  4. formtarget
42. Which of the following HTML5 features is capable of taking a screenshot of a web page?
Answers:
  1. Server-Sent Events
  2. SVG
  3. Canvas
  4. Web Workers
43. Which of the following are true about the ARIA role attribute in HTML5?
Answers:
  1. Every HTML element can have an ARIA role attribute specified.
  2. Every HTML element is required have an ARIA role attribute specified.
  3. The attribute must have a value that is a set of space-separated tokens representing the various WAI-ARIA roles that the element belongs to.
  4. There is no ARIA attribute called “role”.
44. Which of the following video tag attributes are invalid in HTML5?
Answers:
  1. play
  2. loop
  3. mute
  4. pause
45. True or False:HTML5 Canvas can be used to create images.
Answers:
  1. True
  2. False
46. Which of the following statements are correct with regard to the <hr> and <br> elements of HTML5?
Answers:
  1. The <hr> element acts in the same way as the tab key and the <br> element acts in the same way as the shift key.
  2. The <hr> element is used to insert the horizontal line within the document and the <br> element is used to insert a single line break.
  3. The <hr> element is used to put a line across the page and the <br> element acts in the same way as a return/enter key press.

47. The following link is placed on an HTML webpage:<a href=”http://msdn.com/” target=”_blank”> MSDN </a>.What can be inferred from it?
Answers:
  1. It will open the site msdn.com in the same window.
  2. It will open the site msdn.com in a new window.
  3. It will open the site msdn.com in a frame below.
  4. It will not be clickable as it is not formed correctly.
48. Which following are valid default values for the <input type=”date”> HTML5 element?
Answers:
  1. now
  2. 2013-05-30
  3. 2013-30-05
  4. today
49. True or false:JavaScript objects can be stored directly into localStorage.
Answers:
  1. True
  2. False
50. What is the limit to the length of HTML attributes?
Answers:
  1. 65536
  2. 64
  3. There is no limit.
  4. None of these.
51. Which of the following examples contain invalid implementations of the ampersand character in HTML5?
Answers:
  1. foo & bar
  2. foo &0 bar
  3. foo &0; bar
  4. foo&&& bar
52. Which is the standard method for clearing a canvas?
Answers:
  1. context.clearRect ( x , y , w , h );
  2. canvas.width = canvas.width;
  3. context.clear();
  4. All of these.
53. Which of the following <link> attributes are not supported in HTML5?
Answers:
  1. sizes
  2. rev
  3. rel
  4. charset
54. In HTML5, which of the following is not a valid value for the type attribute when used with the <command> tag shown below?
<command type=”?”>Click Me!</command>
Answers:
  1. button
  2. command
  3. checkbox
  4. radio
55. Which of the following attributes gets hidden when the user clicks on the element that it modifies? (Eg. hint text inside the fields of web forms)
Answers:
  1. autocomplete
  2. autofocus
  3. placeholder
  4. formnovalidate
56. Which event is fired when an element loses its focus in an HTML5 document?
Answers:
  1. onfocus
  2. onload
  3. onblur
  4. onselect
57. What is the purpose of the <q> element in HTML5?
Answers:
  1. It is used to define the start of a term in a definition list.
  2. It is used to define attribute values for one or more columns in a table.
  3. It is used to define the start of a short quotation.
  4. It is used to define what to show browsers that do not support the ruby element.
58. Consider the following items of a <select> list:
<option value=”89″>Item 1</option>
<option value=”90″>Item 2</option>
Which of the following values would be passed on by clicking the submit button on selecting Item 2 from the list?
Answers:
  1. 89
  2. 90
  3. Item 1
  4. Item 2
59. Which of the following is the best method to store an array in localStorage?
Answers:
  1. var localStorage[names]=new Array(); localStorage.names[0]=prompt(“New member name?”);
  2. var names = []; names[0] = prompt(“New member name?”); localStorage[“names”] = JSON.stringify(names); var storedNames = JSON.parse(localStorage[“names”]);
  3. Storage.prototype.setObj = function(key, obj) { return this.setItem(key, JSON.stringify(obj)) } Storage.prototype.getObj = function(key) { return JSON.parse(this.getItem(key)) }
  4. localStorage.setItem(‘names_length’, names.length); localStorage.setItem(‘names_0’, names[0]); localStorage.setItem(‘names_1’, names[1]); localStorage.setItem(‘names_’ + n, names[n]);
60. Which of the following are valid HTML5 elements?
Ans:
  1. canvas
  2. summary
  3. aside
  4. video
61. Which of the following are possible ways to make the browser automatically adds new images and discards deleted images with server-side events in HTML5?
Ans:
  1. Long Polling Ajax Requests
  2. Server-sent Events
  3. WebSockets
  4. JavaScript objects on the client via JSON.parse().
62. Which of the following input element variations will show a numeric keypad in mobile browsers?
Ans: 
  1. <input type=”text” pattern=”[0-9]*” />
  2. <input type=”number” />
  3. <input type=”text” keyboard=”numeric” />
  4. <input type=”text” keyboard=”number11″ />
63. Which of the following elements have the correct attribute assignment as per HTML5?
Ans:
a. <section id=”example”>…</section id=”example”>
b. <section id=”example”>…</section id=”example2″>
c. <section id=”EXAMPLE”>…</section>
d. <section id=”Example”>…</section>
e. <section id=”example”>…</section>
64. True or false:
JavaScript objects can be stored directly into localStorage.
Ans: 
  1. True
  2. False
65. What is the proper syntax for a line break tag as W3C specs defines?.
Ans: 
  1.  <br>
  2. </br>
  3. <br/>
  4. All of these
66.Which of the following are valid ways to associate custom data with an HTML5 element?
Ans: 
  1. <tr class=»foo» data-id-type=»4″>
  2.  <tr class=»foo» id-type=»4″>
  3. <tr class=»foo» data-id_type=»4″>
  4. All of the above.
67.Which of the following elements have the correct attribute assignment as per HTML 5.0?
Ans:
  1. <section id=»example»>…</section id=»example»>
  2. <section id=»example»>…</section id=»example2″>
  3. <section id=»EXAMPLE»>…</section>
  4. <section id=»Example»>…</section>
  5. <section id=»example»>…</section>
68.What does the icon attribute of the HTML5 command tag define?
<command icon=»?»>Click Me!</command>
Ans: 
  1. It is used to define the URL of an image to display as the command.
  2. It is used to define the name of the radiogroup this command belongs to.
  3. It is used to define if the command is checked or not.
  4. It is used to define if the command is available or not.
69.Which of the following methods are valid for navigating to a fragment identifier?
http://demo.com/#foo
Note: There may be more than one right answer.
Ans: 
  1. <a name=»foo»>bar</a>;
  2. <a id=»foo»>bar</a>
  3. <div id=»foo»>bar</div>
  4. <div class=»foo»>bar</div>
70.Which of the following events is not supported in HTML5?
Ans: 
  1. oninput
  2. oninvalid
  3. ondrop
  4. onrest
71.Which of the following is an invalid value for the type attribute of a command tag?
Ans: 
  1. checkbox
  2. radio
  3. command
  4. text
72.Which of the following are true regarding the <keygen> tag in HTML5? 
Ans: 
  1. The <keygen> tag specifies a key-pair generator field used for forms.
  2. The <keygen> tag generates a public/private key pair and then creates a certificate request. This certificate request will be sent to a Certificate Authority (CA), which then creates a certificate and sends it back to the browser.
  3. The <keygen> tag generates random passwords when the user requests for a password reset.
  4. The <keygen> tag is deprecated in HTML5.
73. Which of the following is not an attribute of theelement in HTML5?
Ans: 
  1. charset
  2. content
  3. http-equiv
  4. scheme
74.Which of the following is a proper syntax for
tag as W3C specs for HTML5 defines?
Ans: 
  1. <br/>
  2. <br/>
  3. <br>
  4. <br></br>
74.What does the icon attribute of the HTML5 command tag define?
Click Me!
Ans: 
  1. It is used to define the URL of an image to display as the command.
  2. It is used to define the name of the radiogroup this command belongs to.
  3. It is used to define if the command is checked or not.
  4. It is used to define if the command is available or not.
75.Which of the following input element variations will show a numeric keypad in mobile browsers?
Ans: 
  1. <input pattern=”[0-9]*” type=”text” />
  2. <input type=”number” />
  3. <input type=”text” />
  4. <input type=”text” />

No comments:

Post a Comment