Home Interview Questions and Answers JQuery Interview Questions and Answers For Graduates Part-3

jquery21.What is closure?
Closures are created whenever a variable that is defined outside the current scope is accessed from within some inner scope.

22.Give an example of closure?
Following example shows how the variable counter is visible within the create, increment, and print functions, but not outside of them −

function create() {
var counter = 0;

return {
increment: function() {
counter++;
},

print: function() {
console.log(counter);
}
}
}

var c = create();
c.increment();
c.print(); // ==> 1

23.Which built-in method returns the character at the specified index?
charAt() method returns the character at the specified index.

24.Which built-in method combines the text of two strings and returns a new string?
concat() method returns the character at the specified index.

25.Which built-in method calls a function for each element in the array?
forEach() method calls a function for each element in the array.

26.Which built-in method returns the index within the calling String object of the first occurrence of the specified value?
indexOf() method returns the index within the calling String object of the first occurrence of the specified value, or −1 if not found.

27.Which built-in method returns the length of the string?
length() method returns the length of the string.

28.Which built-in method removes the last element from an array and returns that element?
pop() method removes the last element from an array and returns that element.

29.Which built-in method adds one or more elements to the end of an array and returns the new length of the array?
push() method adds one or more elements to the end of an array and returns the new length of the array.

30.Which built-in method reverses the order of the elements of an array?
reverse() method reverses the order of the elements of an array — the first becomes the last, and the last becomes the first.

You may also like

Leave a Comment