Q.1 What will be the output of the following code?
function test() {
console.log(a);
console.log(foo());
var a = 1;
function foo() {
return 2;
}
}
test();
Q.2 What will be the output of the following code?
const person = {
name: 'John',
age: 30
};
const { name: firstName, age: years } = person;
console.log(firstName, years);
Q.3 What will be the output of the following code?
const a = [1, 2, 3];
const b = [...a];
b.push(4);
console.log(a);
Q.4 What will be the output of the following code?
const add5 = x => x + 5;
const multiply2 = x => x * 2;
const compose = (...fns) => x => fns.reduceRight((acc, fn) => fn(acc), x);
const combinedFunction = compose(multiply2, add5);
console.log(combinedFunction(7));
Q.5 What will be the output of the following code?
const obj = {
a: 10,
b: 20,
sum() {
return this.a + this.b;
}
};
const obj1 = {
a: 1,
b: 2
}
const boundSum = obj.sum.bind(obj1);
console.log(boundSum());