JavaScript MCQs with answers Page - 48

Here, you will find a collection of MCQ questions on JavaScript. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 833K Points
Coach

Q. What happens when we run this code?

Code:
function dog() {
   print("I am a dog.");
}
dog.sound = "Bark";
  • (A) Syntax Error
  • (B) “I am a dog” gets printed
  • (C) ReferenceError
  • (D) Nothing happens

A

Admin • 833K Points
Coach

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

Code:
const obj1 = {Name: "Hello", Age: 16};
const obj2 = {Name: "Hello", Age: 16};
print(obj1 === obj2);
  • (A) true
  • (B) false
  • (C) Undefined
  • (D) None of the above

A

Admin • 833K Points
Coach

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

Code:
let n = 24;
let l = 0, r = 100, ans = n;
while(l <= r) {
   let mid = Math.floor((l + r) / 2);
   if(mid * mid <= n) {
       ans = mid;
       l = mid + 1;
   }
   else {
       r = mid - 1;
   }
}
print(ans);
  • (A) 3
  • (B) 4
  • (C) 5
  • (D) 6

A

Admin • 833K Points
Coach

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

A

Admin • 833K Points
Coach

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

A

Admin • 833K Points
Coach

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

A

Admin • 833K Points
Coach

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

A

Admin • 833K Points
Coach

Q. How to stop an interval timer in Javascript?

  • (A) clearInterval
  • (B) clearTimer
  • (C) intervalOver
  • (D) None of the above

A

Admin • 833K Points
Coach

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

  • (A) async
  • (B) await
  • (C) setTimeout
  • (D) None of the above

A

Admin • 833K Points
Coach

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

  • (A) Node
  • (B) Vue
  • (C) React
  • (D) Cassandra

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ