This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “The jQuery Library”.
1. Which of the following is not the feature of jQuery?
a) Efficient query method for finding the set of document elements
b) Expressive syntax for referring to elements in the document
c) Useful set of methods for manipulating selected elements
d) Powerful functional programming techniques is not used for operating on sets of elements as a group
View Answer
Explanation: These features are at the heart of jQuery’s power and utility:
- An expressive syntax (CSS selectors) for referring to elements in the document
- An efficient query method for finding the set of document elements that match a CSS selector
- A useful set of methods for manipulating selected elements
- Powerful functional programming techniques for operating on sets of elements as a group, rather than one at a time
- A succinct idiom (method chaining) for expressing sequences of operations.
2. Which of the following is a single global function defined in the jQuery library?
a) jQuery()
b) $()
c) Queryanalysis()
d) global()
View Answer
Explanation: The jQuery library defines a single global function named jQuery(). This function is so frequently used that the library also defines the global symbol $ as a shortcut for it. The $ sign it’s just an alias to jQuery(), then an alias to a function which is used as a selector element.
3. Which of the following is a factory function?
a) $()
b) jQuery()
c) Queryanalysis()
d) onclick()
View Answer
Explanation: jQuery() is a factory function rather than a constructor: it returns a newly created object but is not used with the new keyword. jQuery objects define many methods for operating on the sets of elements they represent.
4. Which is the JavaScript code that asks for the set of all div elements in a document?
a)
var divs = $(div);
b)
var divs = jQuery("div");
c)
var divs = $("div");
d)
var divs = #("div");
Explanation: :$ sign is used as an selector element and the argument passed to $ function is selected. The code to ask for the set of all div elements in a document is
var divs = $("div");
5. Which is the method that operates on the return value of $()?
a) show()
b) css()
c) click()
d) done()
View Answer
Explanation: The css() method sets or returns one or more style properties for the selected elements. The css() method operates on the jQuery object returned by $(), and returns that same object, so that the show() method can be invoked next in a compact “method chain.”
6. What does the min mean in the following JavaScript code?
<script src="jquery-1.4.2.min.js"></script>
a) Minimised version
b) Miniature
c) Minimised parameters
d) Minimum value
View Answer
Explanation: The min means the minimised version of the library, with unnecessary comments and whitespace removed, and internal identifiers replaced with shorter ones. The file size of minfile is smaller than the original file hence it makes it easier to load.
7. Which of the following is a heavily overloaded function?
a) jQuery()
b) $()
c) script()
d) Both jQuery() and $()
View Answer
Explanation: $() is just an alias function of jquery(). The jQuery() function (a.k.a) $()) is the most important one in the jQuery library. It is heavily overloaded, however, and there are four different ways you can invoke it.
8. Which of the following is an equivalent replacement of $(document).ready(f)?
a) jQuery(f)
b) $(f)
c) #(f)
d) read(f)
View Answer
Explanation: The equivalent replacement of $(document).ready(f) is $(f). Writing $(document) performs the function of selecting the whole document which is the same as writing $() only.
9. Which of the following is a utility function in jQuery?
a) jQuery.each()
b) jQuery.parseJSON()
c) jQuery.noConflict()
d) jQuery.conflict()
View Answer
Explanation: jQuery.noConflict() is the utility function in jQuery. The noConflict() method releases the hold on the $ shortcut identifier, so that other scripts can use it.
10. Which of the following is used for parsing JSON text?
a) jQuery.each()
b) jQuery.parseJSON()
c) jQuery.noConflict()
d) jQuery.conflict()
View Answer
Explanation: jQuery.parseJSON() is used for parsing JSON text. The function converts json to javascript object.
11. What will be the output of the following JavaScript code?
<p id="demo"></p> <script> function myFunction() { var str = "Tables"; var patt1 = /tables/i; var result = str.match(patt1); document.getElementById("demo").innerHTML = result; } </script>
a) Tables
b) tables
c) Undefined
d) Error
View Answer
Explanation: The i modifier is used to perform case-insensitive matching. It is found in the regex library of Javascript.
12. What will be the output of the following JavaScript code?
<script> var str = "The rain in Spain"; var patt1 = /ain/g; document.write(patt1.lastIndex); </script>
a) 8
b) 17
c) 14
d) 10
View Answer
Explanation: The lastIndex property specifies the index at which to start the next match. This property only works if the “g” modifier is set.
13. What will be the output of the following JavaScript code?
<p id="demo"></p> <script> function myFunction() { var str = "\nIs th\nis it?"; var patt1 = /^is/m; var result = str.match(patt1); document.getElementById("demo").innerHTML = result; } </script>
a) IS
b) is
c) Error
d) Undefined
View Answer
Explanation: The m modifier is used to perform a multiline match. The m modifier treat beginning (^) and end ($) characters to match the beginning or end of each line of a string (delimited by \n or \r), rather than just the beginning or end of the string.
14. What will be the output of the following JavaScript code?
<p id="demo"></p> <script> function myFunction() { var str = "Hellooo World!"; var patt1 = /o+/g; var result = str.match(patt1); var count=0; While(result[i]!=NULL) { If(result[I]==o) count++; } document.getElementById("demo").innerHTML = count; } </script>
a) 4
b) 3
c) 1
d) 0
View Answer
Explanation: The o+ quantifier matches any string that contains at least one o. It concatenates the total number of o in a string.
15. What will be the output of the following JavaScript code?
<p id="demo"></p> <script> function myFunction() { var str = "Is this his"; var patt1 = /is$/g; var result = str.match(patt1); if(result) result='true'; else result='false'; document.getElementById("demo").innerHTML = result; } </script>
a) true
b) false
c) error
d) undefined
View Answer
Explanation: The n$ quantifier matches any string with n at the end of it. The above string has words ending with is therefore the output will be true.
Sanfoundry Global Education & Learning Series – Javascript Programming.
- Get Free Certificate of Merit in JavaScript
- Participate in JavaScript Certification Contest
- Become a Top Ranker in JavaScript
- Take JavaScript Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for Information Technology Internship
- Buy Programming Books
- Practice Programming MCQs
- Apply for JavaScript Internship
- Buy JavaScript Books