JavaScript Questions & Answers – Scripted Media

«
»

This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Scripted Media”.

1. What is the advantage of the code produced graphics being smaller than the images themselves?
a) Bandwidth saving
b) Increase in bandwidth
c) Dynamic advantages
d) Static advantage
View Answer

Answer: a
Explanation: The code used to produce graphics on the client side is typically much smaller than the images themselves, creating substantial bandwidth savings.
advertisement

2. Which of the following uses a lot of CPU cycles?
a) GUI
b) Statically generated graphics
c) Dynamically generated graphics
d) Images
View Answer

Answer: c
Explanation: Dynamic graphics for data, means simulating motion or movement using the computer. It may also be thought of as multiple plots linked by time. Dynamically generating graphics from real-time data uses a lot of CPU cycles.

3. Which HTML element is used to include images?
a) image
b) img
c) src
d) sourcing
View Answer

Answer: b
Explanation: Web pages include images using the HTML img element. src tag is used to include the image link.

4. What is the purpose of image replacement?
a) To replace an image
b) To implement special effects
c) Removal of image rollovers
d) Implementation of image rollovers
View Answer

Answer: d
Explanation: Image replacement is a technique developed to allow designers to use image-based typesetting while meeting accessibility requirements. One common use for image replacement is to implement image rollovers, in which an image changes when the mouse pointer moves over it.

5. When is JavaScript called obtrusive?
a) JavaScript code is medium sized
b) JavaScript code is small
c) JavaScript code is so large
d) JavaScript code is Very small
View Answer

Answer: c
Explanation: When the amount of JavaScript code is so large that it effectively obscures the HTML, we call JavaScript as obtrusive. On the other hand unobtrusive JavaScript is a best practice methodology for attaching JavaScript to the front-end of a website.

6. Which is a possible way of finding all the img elements in the document?
a) document(images)
b) document.images[]
c) document(img)
d) doc(img)
View Answer

Answer: b
Explanation: The best suited option is document.image[] to find all img elements in the document.[index] is used to specify the index of which img tag is to be selected.

7. Which of the following elements are used to include audio?
a) audio
b) video
c) svg
d) aud
View Answer

Answer: a
Explanation: The audio tag is used to include audio in the HTML document. The audio tag includes method like play(), pause() etc.
advertisement

8. Which of the following attributes are common to both audio and video?
a) enter
b) control
c) controls
d) add
View Answer

Answer: c
Explanation: Both audio and video support a controls attribute. When present, it specifies that audio controls should be displayed. Both audio and video support a controls attribute.

9. Which of the following is not the property of the video tag?
a) width
b) height
c) breadth
d) area
View Answer

Answer: c
Explanation: The video tag does not contain a breadth property. The width and height property specifies the width and height of the video.

10. Which of the following is the parameter used to invoke the Audio() constructor?
a) File type
b) Music type
c) Both File and Music
d) Video type
View Answer

Answer: c
Explanation: The HTMLAudioElement interface provides access to the properties of <audio> elements, as well as methods to manipulate them. It derives from the HTMLMediaElement interface. The parameter type of the Audio() constructor is any file type that contains audio to be played.

11. What will be the output of the following JavaScript code?

<p id="demo"></p>
<script>
function myFunction() 
{
   var num = 098;
   var n = num.valueOf()
   document.getElementById("demo").innerHTML = n;
}
</script>

a) 098
b) 98
c) Error
d) Undefined
View Answer

Answer: b
Explanation: The valueOf() method returns the primitive value of a number. The value of num in the above case would be 98.

12. What will be the output of the following JavaScript code?

advertisement
<p id="demo"></p>
<script>
function myFunction() 
{
   var num = 3+2;
   var n = num.valueOf()
   document.getElementById("demo").innerHTML = n;
}
</script>

a) 5
b) 3+2
c) Error
d) Undefined
View Answer

Answer: a
Explanation: The valueOf() method returns the primitive value of a number. It performs the calculations in the number and then displays the result.

13. What will be the output of the following JavaScript code?

<p id="demo"></p>
<script>
function myFunction() 
{
   var num = 13.3714;
   document.getElementById("demo").innerHTML = num.toPrecision(3);
}
</script>

a) 13
b) 13.3714
c) 13.3
d) 13.4
View Answer

Answer: d
Explanation: The toPrecision() method formats a number to a specified length. A decimal point and nulls are added (if needed), to create the specified length.

14. What will be the output of the following JavaScript code?

<script>
var num = new Number(1000000).toLocaleString("fi-FI");
document.write(num);
</script>

a) 1 000 000
b) 1 0 00000
c) 100 000 0
d) Undefined
View Answer

Answer: a
Explanation: This method formats a number into a string, using language specific format. In this example we use the “fi-FI” value to specify the locale number format in FINLAND.

15. What will be the output of the following JavaScript code?

advertisement
<p id="demo"></p>
<script>
function myFunction() 
{
   document.getElementById("demo").innerHTML = Number.POSITIVE_INFINITY;
}
</script>

a) 10000
b) -infinity
c) infinity
d) error
View Answer

Answer: c
Explanation: The POSITIVE_INFINITY property represents positive infinity. Positive infinity can be explained as something that is higher than any other number.

Sanfoundry Global Education & Learning Series – Javascript Programming.

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn