243). What convenience does the following JavaScript code snippet provide?
let succ = function(x) x+1, yes = function() true, no = function() false;
[A] Functional behaviour
[B]Modular behaviour
[C] No convenience
[D]Shorthand expression
Show Answer
Correct Answer: Functional behaviour
Notes:
Answer: a
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.
244). What does the following JavaScript code snippet do?
data.sort(function(a,b),b-a);
[A]Sort in the alphabetical order
[B]Sort in the chronological order
[C]Sort in reverse alphabetical order
[D] Sort in reverse numerical order
Show Answer
Correct Answer: Sort in reverse numerical order
Notes:
Answer: d
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.
245). What is the code to be used to trim whitespaces?
data.sort(function(a,b),b-a);
[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));
Show Answer
Correct Answer: let trimmed = (l.trim() for (l in lines));
Notes:
Answer: a
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.
246). What will be the reaction when a catch clause has no conditionals?
data.sort(function(a,b),b-a);
[A]Takes it to be 0
[B]Takes it to be 1
[C]Takes it to be true
[D] Takes it to be false
Show Answer
Correct Answer: Takes it to be true
Notes:
Answer: c
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.
247). When will the finally block be called?
data.sort(function(a,b),b-a);
[A]When there is no exception
[B]When the catch does not match
[C]When there is exception
[D]After try-catch execution
Show Answer
Correct Answer: After try-catch execution
Notes:
Answer: d
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.
248). What is the return type of typeof for standard JavaScript objects?
data.sort(function(a,b),b-a);
[A]xml
[B]object
[C]dom
[D]html
Show Answer
Correct Answer: object
Notes:
Answer: b
Explanation: The typeof operator returns “object” for all standard JavaScript objects. It returns “object” for a null, “number” for NaN, “number” for Infinity, “object” for a “new Number(1)” and “object” for an array.
249). Which method to use while working with XML fragments, instead of XML()?
data.sort(function(a,b),b-a);
[A]XMLInterface()
[B]XMLClass()
[C]XMLList()
[D]XMLArray()
Show Answer
Correct Answer: XMLList()
Notes:
Answer: c
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().
250). Which of the following is the descendant operator?
data.sort(function(a,b),b-a);
Show Answer
Correct Answer: ..
Notes:
Answer: a
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:
251). Which of the following is an example to perform the most common XML manipulations using the XML objects invocation?
data.sort(function(a,b),b-a);
[A]insertChildBefore()
[B]insertChildAfter()
[C]appendChildAfter(…)
[D]appendChildBefore(…)
Show Answer
Correct Answer: insertChildBefore()
Notes:
Answer: a 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:
252). What is the code required to delete all “weight” tags?
data.sort(function(a,b),b-a);
[A]delete weight(pt).all;
[B] delete pt.element[all];
[C]delete pt;
[D]delete pt..weight;
Show Answer
Correct Answer: delete pt..weight;
Notes:
Answer: d
Explanation: Delete is a keyword in javascript which is used for deleting objects ,pointers and variables. Removing attributes and tags is very easy with the standard delete operator :
253). What will be the output of the following JavaScript code?
[A]30
[B]10 20
[C]1020
[D]Error
Show Answer
Correct Answer: 1020
Notes:
Answer: c
Explanation: If a number and a numeric string is added, then the result will be a concatenated string. The two numbers will not be added as they are of different types.
254). What will be the output of the following JavaScript code?
[A]1020
[B]10 20
[C]30
[D]Error
Show Answer
Correct Answer: 1020
Notes:
Answer: a
Explanation: The two numbers will not get and rather get concatenated as string. Therefore the output will be 1020.
255). What will be the output of the following JavaScript code?
[A]1000
[B]10
[C]10010
[D]Error
Show Answer
Correct Answer: 1000
Notes:
Answer: a
Explanation: JavaScript will try to convert strings to numbers when multiplying. Therefore the two values will be converted to numbers and multiplied.
256). What will be the output of the following JavaScript code?
[A]true
[B]false
[C]error
[D]undefined
Show Answer
Correct Answer: false
Notes:
Answer: b
Explanation: In the above code an object and a number are compared. When different data types are compared then the answer is false.
257). What will be the output of the following JavaScript code?
[A]10
[B]9.65
[C]9.6
[D]9.656
Show Answer
Correct Answer: 10
Notes:
Answer: a
Explanation: toFixed() method rounds off the number to specified number of decimal places. Since the argument is passed with 0 value therefore the output will be 10.
258). What will be the output of the following JavaScript code?
[A]8.70
[B]8.76
[C]8.00
[D]Error
Show Answer
Correct Answer: 8.00
Notes:
Answer: c
Explanation: The trunc() method returns the integer part of a number. This method will NOT round the number up/down to the nearest ingeger, but simply remove the decimals.
259). What will be the output of the following JavaScript code?
[A]2.00
[B]2.10
[C]2.20
[D]2.30
Show Answer
Correct Answer: 2.30
Notes:
Answer: d
Explanation: The LN10 property returns the natural logarithm of 10, approximately 2.302. The method is find in the math library of Javascript.
260). What will be the output of the following JavaScript code?
[A]1.31
[B]1.20
[C]1.11
[D]1.41
Show Answer
Correct Answer: 1.31
Notes:
Answer: a
Explanation: The acosh() method returns the hyperbolic arccosine of a number. If the parameter x is less than 1, the method will return NaN.