1. Consider the following code snippet
let succ = function(x) x+1, yes = function() true, no = function() false;
What convenience does the above code snippet provide?
a) Functional behaviour
b) Modular behaviour
c) No convenience
d) Shorthand expression
Explanation: The functions defined in this way behave exactly like functions defined with curly braces and the return keyword.
2. Consider the following code snippet
What does the above code do?
a) Sort in the alphabetical order
b) Sort in the chronological order
c) Sort in reverse alphabetical order
d) Sort in reverse numerical order
Explanation: The above code snippet sorts an array in reverse numerical order.
3. What is the code to be used to trim whitespaces ?
a) let trimmed = (l.trim() for (l in lines)); b) let trimmed = (trim(l)); c) let trimmed = l.trim(); d) let trimmed = for(l in lines));
Explanation: We can use the above code to trim whitespaces and filter out comments and blank lines.
4. What will be the reaction when a catch clause has no conditionals ?
a) Takes it to be 0
b) Takes it to be 1
c) Takes it to be true
d) Takes it to be false
Explanation: If a catch clause has no conditional, it behaves as if it has the conditional if true, and it is always triggered if no clause before it was triggered.
5. When will the finally block be called?
a) When there is no exception
b) When the catch doesnot match
c) When there is exception
d) None of the mentioned
Explanation: A finally block is called after try-catch execution.
7. Which method to use while working with XML fragments, instead of XML()?
Explanation: When working with XML fragments, use XMLList() instead of XML():
pt.element += new XMLList('<element id="6"><name>Carbon</name></element>'+'<element id="7"><name>Nitrogen</name></element>');
8. Which of the following is the descendant operator?
Explanation: The .. operator is the descendant operator; you can use it in place of the normal . member-access operator :
var names = pt..name;
9. Which of the following is an example to perform the most common XML manipulations using the XML objects invocation?
Explanation: E4X is designed so that you can perform most common XML manipulations using language syntax. E4X also defines methods you can invoke on XML objects. Here, for example, is the insertChildBefore() method:
10. What is the code required to delete all “weight” tags?
a) delete weight(pt).all;
b) delete pt.element[all];
c) delete pt;
d) delete pt..weight;
Explanation: Removing attributes and tags is very easy with the standard delete operator :
delete pt..weight; //delete all <weight> tags