HTML Questions & Answers – Essential JavaScript and jQuery – 1

This set of HTML Multiple Choice Questions & Answers (MCQs) focuses on “Essential JavaScript and jQuery – 1”.

1. External scripts can’t take the tag _________
a) <script>
b) <form>
c) <h1>
d) <title>
View Answer

Answer: a
Explanation: We used external JavaScript code by saving is as .js extension, we can’t use <script> tag in external JavaScript file. For using external script, we can use src attribute and put file name inside it with <script> tag.

Syntax is <script src=”external_file.js”></script>.

When one wants to write a message in console, console.log() is used. The window.alert() alerts message in box on window.

advertisement
advertisement

2. For displaying data in JavaScript, we can’t use ____________
a) document.write()
b) console.log()
c) innerHTML
d) document.getElementById()
View Answer

Answer: d
Explanation: We can display data in many ways in JavaScript.They are innerHTML, console.log(), window.alert(), document.write. document.getElementById(id) is a method used for accessing HTML element by JavaScript. Here id defines the HTML element.

3. For testing we should use ________
a) document.write()
b) console.log()
c) window.alert()
d) innerHTML
View Answer

Answer: a
Explanation: For testing we used document.write() in JavaScript. If we use document.write() after HTML document, it will delete all existing HTML. This method can only be used for testing purposes.

 <script> document.write(9*6); </script>

4. Which of the following keyword stops the execution of JavaScript?
a) break
b) return
c) debugger
d) try….catch
View Answer

Answer: c
Explanation: By using debugger keyword execution of JavaScript stops, and is debugger function is defined it is called at the moment, break is the keyword used to terminate a loop or a switch, return is used for exit from a function, try…catch handle the errors.
advertisement

5. Arrays in JavaScript are written within ____________
a) {}
b) [].
c) “”
d) ()
View Answer

Answer: b
Explanation: Arrays in JavaScript are written in square brackets. The elements of array are separated by commas. Index of array items starts from 0. E.g. var fruits= [“apple”, “orange”, “banana”, “pine-apple”]; objects in JavaScript are written inside curly brackets.

6. typeof “null” in JavaScript is _______
a) number
b) string
c) object
d) undefined
View Answer

Answer: c
Explanation: typeof “null” in JavaScript is an object. Basically null indicates nothing like it is a thing that does not exist. It is like a bug in JavaScript that its typeof comes to be an object. For emptying an object we can set it to null.
advertisement

7. Negative positions for string do not work in ______________
a) Internet Explorer 8
b) Chrome
c) Safari
d) Opera
View Answer

Answer: a
Explanation: While using slice(), substr() and substring() method we pass numbers as parameters respective to the string. E.g var tes= str.slice(-10). -10 is indicates negative position. It does not work in Internet Explorer or older versions.

8. For converting string to array we can use ______________ method.
a) charAt()
b) charCodeAt()
c) split()
d) toLowerCase()
View Answer

Answer: c
Explanation: For converting any string to an array we use split() method. E.g. var tr=”t,o,I,k,l”; tr.split(“,”); tr.split(“|”); tr.split(“ ”); charAt returns a character from the given index, charCodeAt() returns Unicode of character at the given index. toLowerCase() method converts input string into lower case string.

9. JavaScript numbers are stored as ______________
a) integers
b) double precision floating point
c) double
d) floating point
View Answer

Answer: b
Explanation: The numbers according to international IEEE 754 standard are stored as a double precision floating point. It stores the numbers in 64-bit format, stored in bits from 0 to 51, exponent in bits is from 52 to 62 and signs in a bit is 63.

10. The integers in JavaScript are precise up to ___________
a) 12 digits
b) 10 digits
c) 23 digits
d) 15 digits
View Answer

Answer: d
Explanation: The integers in JavaScript have accuracy up to 15 digits. E.g. var y=111111111111111; // value of y will be 111111111111111. For decimal the maximum number of decimals is 17.

11. Typeof “infinity” will return ___________
a) string
b) number
c) object
d) undefined
View Answer

Answer: b
Explanation: The typeof “infinity” will return number. E.g. typeof Infinity; // it will return “number”, when we divide any number by zero it will generate infinity.

Syntax is var number=9; while(number != Infinity) { number= number + number; }

12. By default JavaScript displays the numbers as ___________
a) base 16
b) base 10
c) base 6
d) base 2
View Answer

Answer: b
Explanation: base 10 decimals are displayed as numbers by default by JavaScript. We can use toString() method for converting numbers as any of the base among 16, 2, 8. E.g var number= 1256; number.toString(6); number.toString(16); number.toString(2).

13. Which method is not used for converting variables to number?
a) parseInt()
b) Number()
c) parseFloat()
d) valueOf()
View Answer

Answer: d
Explanation: There are mainly three methods with the help of those we can convert variables to numbers. The methods are the parseFloat() method, the Number() method, the parseInt() method. These are global JavaScript methods. valueOf() method return number as a number only.

14. Math.random() returns _______________
a) random number between 0 and 1
b) random number between 1 and 10
c) random number between 1 and 100
d) random number between 0 and 10
View Answer

Answer: a
Explanation: Math.random() generate any random number between 0 and 1. If we use Math.random() with Math.floor() it returns any random integer. E.g. Math.floor(Math.random * 1000); It will generate any random number between 0 and 999. For the sake of convenience we can also define a random function.

15. What is the Boolean value of “” in JavaScript?
a) true
b) on
c) off
d) false
View Answer

Answer: d
Explanation: For an empty string (“”), the Boolean value is false. E.g. var t= “ ”; Boolean(t); //it will return false. For -0(minus zero), the Boolean value is false. The Boolean value of undefined is also false. For null and false the Boolean value is also false.

Sanfoundry Global Education & Learning Series – HTML.

To practice all areas of HTML, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.