JavaScript Questions & Answers – The jQuery Library

«
»

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

Answer: d
Explanation: These features are at the heart of jQuery’s power and utility:

  1. An expressive syntax (CSS selectors) for referring to elements in the document
  2. An efficient query method for finding the set of document elements that match a CSS selector
  3. A useful set of methods for manipulating selected elements
  4. Powerful functional programming techniques for operating on sets of elements as a group, rather than one at a time
  5. 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

Answer: a
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

Answer: b
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.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement

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)

advertisement
 var divs = $("div");

d)

advertisement
var divs = #("div");
View Answer
Answer: c
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

Answer: b
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

Answer: a
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

Answer: d
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

Answer: b
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

Answer: c
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

Answer: b
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

Asnwer: a
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

Answer: b
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

Answer: b
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

Answer: a
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

Answer: a
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.

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 & technical discussions at Telegram SanfoundryClasses.