Signup/Sign In

Guess the Output - Part 6 Test

JavaScript Avg. Score: 2.3 172 Intermediate
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());

Studytonight logo

Find me on YouTube

I make videos for Fullstack Dev, AWS, Ethical Hacking and Foundational stuff.