Q61. How to stop event bubbling ?
Q62. What is the use of Array.map()?
Q63. How you can join two arrays into third array in JavaScript?
Q64. What is Slice operator on Array? How it is different from Spread operator?
Q65. What 'this' keyword denotes in JavaScript?
---------------------------------------------------------------------------------------------------------------------------
Q61. How to stop event bubbling ?
Answer:
event.stopPropagation()
---------------------------------------------------------------------------------------------------------------------------
Q62. What is the use of Array.map()?
Answer:
The map() method creates a new array with the results of calling a new function or inline logic.
eg
var numbers = [65, 44, 12, 4];
var newarray1 = numbers.map(doubleFunction)
var newarray2 = numbers.map(x=>x*2)
function doubleFunction(num) {
return num * 10;
}
---------------------------------------------------------------------------------------------------------------------------
Q63. How you can join two arrays into third array in JavaScript?
Answer:
Two ways by which we can concatinate two arrays in javascript
1. Concat
2. Spread
// 2 Ways to Merge Arrays
const cars = ['🚗', '🚙'];
const trucks = ['🚚', '🚛'];
// Method 1: Concat
const combined1 = [].concat(cars, trucks);
// Method 2: Spread
const combined2 = [...cars, ...trucks];
---------------------------------------------------------------------------------------------------------------------------
Q64. What is Slice operator on Array? How it is different from Spread operator?
Answer:
The slice() method returns the selected elements in an array, as a new array object. We can say Slice operator can be used to create a deep copy.
array.slice(start, end)
Example:
var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = fruits.slice(0, 5); //This will copy all elements of fruits array by values (deep copy). By deafult copying of array in javascript is by reference. Now making changes in one array will not effect the other array as they are deep copoied.
Spread Operator:
Like slice method, spread operator can be used to create a copy but it is shallow copy (it also creates a copy by value on array).
---------------------------------------------------------------------------------------------------------------------------
Q65. What 'this' keyword denotes in JavaScript?
Answer:
This in case of inside a method refers to the instance of that method
for example:
var person = {
firstName: "John",
lastName : "Doe",
id : 5566,
fullName : function() {
return this.firstName + " " + this.lastName;
}
};
---------------------------------------------------------------------------------------------------------------------------