javascript snippets interview questions set 2



For the previous set please refer to javascript snippets questions set 1.

Let's  begin with set 2,

Q6)What is the result of running this code?

sum(10, 20);

diff(10, 20);

function sum(x, y) {

  return x + y;

}

let diff = function (x, y) {

  return x - y;

};

 a) 30, ReferenceError, 30, -10

 b) 30, ReferenceError

 c) 30, -10

 d) ReferenceError, -10


Q7)Which of the following values is not a Boolean false?

 a) Boolean(0)

 b) Boolean("")

 c) Boolean(NaN)

 d) Boolean("false")



Q8)For the following class, how do you get the value of 42 from an instance of X?

class X {

  get Y() {

    return 42;

  }

}

a) x.get('Y')

b) x.Y

c) x.Y()

d) x.get().Y



 Q9)What's one difference between the async and defer attributes of the HTML script tag?

 a) The defer attribute can work synchronously.

 b) The defer attribute works only with generators.

 c) The defer attribute works only with promises.

 d) The defer attribute will asynchronously load the scripts in order.


Q10)What value does the code return?

let answer = true;

if (answer === false) {

  return 0;

} else {

  return 10;

}

a) 10

b) false

c)  0



Q11)What is the result in the console of running the code shown?

var start = 1;

function setEnd() {

  var end = 10;

}

setEnd();

console.log(end);

 a) 10

 b) 0

 c) ReferenceError

 d) undefined


I hope you like the article. Please stay connected for more such articles.

Please check the comment section for answers and if any doubts let me know there. 


You can also follow me on Twitter or Linkedin for the latest updates.

Written By:

Saurabh Joshi

Comments

Post a Comment

Popular Posts