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. The above code makes the expression short and reduces the line of code.
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: ’a-b’ is used to sort the array in ascending order whereas ‘b-a’ is used to sort the array in descending order. Therefore 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: The various types of trim functions are trimLeft(), trimRight() and trim().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: The try and catch statement handles some or all of the errors that may occur in a block of code, while still running code. 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 does not match
c) When there is exception
d) After try-catch execution
Explanation: The try and catch statement handles some or all of the errors that may occur in a block of code, while still running code. A finally block is called after try-catch execution.
7. Which method to use while working with XML fragments, instead of XML()?
Explanation: An XML fragment is an XML document with no single top-level root element. When working with XML fragments, use XMLList() instead of XML().
8. Which of the following is the descendant operator?
Explanation: While the . operator accesses direct children of the given node, the .. operator accesses all children no matter how deeply nested: 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;
delete pt..weight; //delete all <weight> tags