ExamVeda
Login
Home
51
The main difference between the variables declared with var and with let is
Discuss
Answer & Solution
Answer: Option B
Solution:
Variables declared with var are defined throughout the enclosing function. Variables declared with let are defined only within the closest enclosing block (and any blocks nested within it, of course).
52
Consider the following code snippet
function oddsums(n) 
{
     let total = 0, result=[]; 
     for(let x = 1; x <= n; x++) 
     { 
        let odd = 2*x-1; 
        total += odd;
        result.push(total);
     }
     return result;
}

What would be the output if
oddsums(5);
is executed afted the above code snippet ?
Discuss
Answer & Solution
Answer: Option A
Solution:
The above code returns 1,4,9,16,25 which is the square of the first five natural numbers. Notice the usage of let keyword in the above code snippet.
53
Consider the following code snippet
console.log(p)
If p is not defined, what would be the result or type of error?
Discuss
Answer & Solution
Answer: Option C
Solution:
In the above code snippet, p is not defined. Hence, it gives a ReferenceError.
54
Consider the following code snippet
let x=x+1;
console.log(x);
What will be the result for the above code snippet?
Discuss
Answer & Solution
Answer: Option D
Solution:
Since x is a let variable and since x is undefined, so x+1 is NaN. Thus, the above code snippet prints NaN.
55
Consider the following code snippet
[x,y]=[y,x];
What is the result of the above code snippet?
Discuss
Answer & Solution
Answer: Option C
Solution:
The above code snippet swaps the value of the two variables.
56
Which looping statement allows XML tags to appear in JavaScript programs and adds API for operating on XML data?
Discuss
Answer & Solution
Answer: Option C
Solution:
The for/each loop is a new looping statement standardized by E4X. E4X (ECMAScript for XML) is a language extension that allows XML tags to appear literally in JavaScript programs and adds syntax and API for operating on XML data.
57
Which exception does the Iterators throw from their next() method when there are no more values to iterate, that work on finite collections ?
Discuss
Answer & Solution
Answer: Option D
Solution:
Iterators that work on finite collections throw StopIteration from their next() method when there are no more values to iterate. StopIteration is a property of the global object in JavaScript 1.7. Its value is an ordinary object (with no properties of its own) that is reserved for this special purpose of terminating iterations. Note, in particular,that StopIteration is not a constructor function like TypeError() or RangeError().
58
Which method of the iterable object returns an iterator object for the collection?
Discuss
Answer & Solution
Answer: Option B
Solution:
An iterable object represents a collection of values that can be iterated. An iterable object must define a method named __iterator__() (with two underscores at the start and end of the name) which returns an iterator object for the collection.
59
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?
Discuss
Answer & Solution
Answer: Option A
Solution:
The functions defined in this way behave exactly like functions defined with curly braces and the return keyword.
60
Consider the following code snippet
data.sort(function(a,b),b-a);
What does the above code do?
Discuss
Answer & Solution
Answer: Option D
Solution:
The above code snippet sorts an array in reverse numerical order.