jQuery Quiz Questions 1-10
There will be an interactive jQuery quiz released soon in the members section where you can win prizes. In the meantime, here are a few jQuery questions which didn’t make the quiz but I thought it would be nice to share them with you, might be useful for some of you trying to learn jQuery or creating a quiz of your own. Hey, you may even learn something you didn’t know about jQuery. There are quite a few questions, here are questions 1-10. Enjoy!
Question 1
Which of the following elements can you attach jQuery events to?
Answers
- object
- embed
- applet
- None of the above
Correct Answer
None of the above
You cannot attach events to object, embed, applet elements. jQuery’s event system requires that a DOM element allows attaching data via a property on the element, so that events can be tracked and delivered.
Question 2
Is the following statement true or false?
jQuery’s event system requires that a DOM element allows attaching data via a property on the element, so that events can be tracked and delivered.
Answers
- true
- false
Correct Answer
true
Question 3
Is the following statement true or false?
jQuery defines focusin and focusout events which are a cross-browser of the focus and blur events.
Answers
- true
- false
Correct Answer
true
The focus and blur events are specified by the W3C to not bubble, but jQuery defines cross-browser focusin andfocusout events that do bubble. When focus and blur are used to attach delegated event handlers, jQuery maps the names and delivers them as focusin and focusout respectively. For consistency and clarity, use the bubbling event type names.
Question 4
Which code is faster?
Answers
- $(‘#test1, .test2, .test3, .test4’);
- $(‘#test1’).add(‘.test2’).add(‘.test3’).add(‘.test4’);
Correct Answer
$(‘#test1, .test2, .test3, .test4’); //faster
jsperf: http://jsperf.com/multiple-jquery-id-selects/2
API: http://api.jquery.com/add/
Question 5
$.grep(array1, function1);
The above statement ___ the elements of array1 array which satisfy function1 function.
Answers
- sorts
- updates
- removes
- filters
Correct Answer
filters
API: http://api.jquery.com/jQuery.grep/
Question 6
Consider the following code snippet:
- Items 1
- Items 2
- Items 3
Which of the following code snippets returns the same result as $(‘#id1 li’).not($(‘#li2’));?
Answers
- $(‘#li2’).siblings();
- $(‘#id2’).siblings(‘#li2’);
- $(‘#li2’).children();
- $(‘#id2’).children(‘#li2’);
Correct Answer
$(‘#li2’).siblings();
see answer in action: https://jsfiddle.net/jquery4u/pHtbq/
Question 7
The hide() function hides an element by ____.
Answers
- setting “display” inline style attribute of that element to “none”.
- setting “visibility” inline style attribute of that element to “hidden”.
- setting the horizontal attribute of that element to “-100px” off visible screen.
- setting the vertical attribute of that element to “-100px” off visible screen.
Correct Answer
setting “display” inline style attribute of that element to “none”.
API: http://api.jquery.com/hide/
Question 8
Which of the following is the correct way to create a div element with a link text “Hello” with jQuery?
Answers
- $(“#idName”).create(“div”).text(“Hello“);
- $(“#idName”).create(“div”).html(“Hello“);
- $(“idName”).css(“div”).html(“Hello“);
- $(“#idName”).append(“Hello“);
Correct Answer
$(“#idName”).append(“Hello“);
Question 9
Consider the following code snippet?
function function1()
{
alert(arguments.length());
}
Which of the following is true when you run function1();?
Answers
- An error occurs because arguments variable is undefined.
- An error occurs because you call function1 with no arguments.
- The alert box displays “undefined”.
- The alert box displays 0.
Correct Answer
An error occurs because you call function1 with no arguments.
Uncaught TypeError: Property ‘length’ of object #
Question 10
$.extend(false, object0, object1, object2);
What does the code above do?
Answers
- Extends the object0 by merging object1 and object2 with object0.
- Extends the object1 by merging object0 and object2 with object1.
- Extends the object2 by merging object0 and object1 with object2.
- The statement is invalid because its arguments are invalid.
Correct Answer
Extends the object0 by merging object1 and object2 with object0.
API: http://api.jquery.com/jQuery.extend/