Q. What will be the output of the following code snippet?

Code:
let s = "00000001111111";
let l = 0, r = s.length - 1, ans = -1;
while(l <= r) {
   var mid = Math.floor((l + r) / 2);
   if(s[mid] == '1') {
       ans = mid;
       r = mid - 1;
   }
   else {
       l = mid + 1;
   }
}
print(ans);
  • (A) 8
  • (B) 7
  • (C) 0
  • (D) 1
πŸ’¬ Discuss
βœ… Correct Answer: (B) 7

Q. What will be the output of the following code snippet?

Code:
let a = [1, 2, 3, 4, 5, 6];
var left = 0, right = 5;
var found = false;
var target = 5;
while(left <= right) {
   var mid = Math.floor((left + right) / 2);
   if(a[mid] == target) {
       found = true;
       break;
   }
   else if(a[mid] < target) {
       left = mid + 1;
   }
   else {
       right = mid - 1;
   }
}
if(found) {
   print("YES");
}
else {
   print("NO");
}
  • (A) YES
  • (B) NO
  • (C) Syntax Error
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (A) YES

Q. What will be the output of the following code snippet?

Code:
const example = ({ a, b, c }) => {
 console.log(a, b, c);
};
example(0, 1, 2);
  • (A) 0 1 2
  • (B) 0 Undefined Undefined
  • (C) Undefined Undefined Undefined
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (C) Undefined Undefined Undefined

Q. What does … operator do in JS?

  • (A) It is used to spread iterables to individual elements
  • (B) It is used to describe a datatype of undefined size
  • (C) No such operator exists
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (A) It is used to spread iterables to individual elements

Q. How are objects compared when they are checked with the strict equality operator?

  • (A) The contents of the objects are compared
  • (B) Their references are compared
  • (C) Both A and B
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (B) Their references are compared

Q. What will be the output of the following code snippet?

Code:
const set = new Set();
set.add(5);
set.add('Hello');
set.add({ name: 'Scaler' });
for (let item of set) {
 console.log(item + 6);
}
  • (A) 11 NaN NaN
  • (B) 11 NaN [object Object]
  • (C) 11 Hello6 [object Object]6
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (C) 11 Hello6 [object Object]6

Q. How to stop an interval timer in Javascript?

  • (A) clearInterval
  • (B) clearTimer
  • (C) intervalOver
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (A) clearInterval

Q. What keyword is used to declare an asynchronous function in Javascript?

  • (A) async
  • (B) await
  • (C) setTimeout
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (A) async

Q. What will be the output of the following code snippet?

Code:
var a = "hello";
var sum = 0;
for(var i = 0; i < a.length; i++) {
   sum += (a[i] - 'a');
}
print(sum);
  • (A) 47
  • (B) NaN
  • (C) 0
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (B) NaN

Q. Which of the following is not a Javascript framework?

  • (A) Node
  • (B) Vue
  • (C) React
  • (D) Cassandra
πŸ’¬ Discuss
βœ… Correct Answer: (D) Cassandra