JavaScript MCQs with answers Page - 36

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 is true about Arrays?

  • (A) JavaScript does not support associative arrays
  • (B) You should use objects when you want the element names to be strings
  • (C) You should use arrays when you want the element names to be numbers
  • (D) All of the above

A

Admin • 833K Points
Coach

Q. The easiest way to add a new element to an array is using the _________ method

  • (A) set()
  • (B) push()
  • (C) insert()
  • (D) add()

A

Admin • 833K Points
Coach

Q. The _______ method also joins all array elements into a string.

  • (A) shift()
  • (B) pop()
  • (C) join()
  • (D) toString()

A

Admin • 833K Points
Coach

Q. Array elements can be deleted using the JavaScript operator?

  • (A) pop
  • (B) shift
  • (C) delete
  • (D) All of the above

A

Admin • 833K Points
Coach

Q. arrays always use numbered indexes.

  • (A) No
  • (B) Yes
  • (C) can be yes or no
  • (D) can

A

Admin • 833K Points
Coach

Q. Which of the following is a JavaScript data type?

  • (A) null
  • (B) undefined
  • (C) object
  • (D) All of the above

A

Admin • 833K Points
Coach

Q. What will be the output of the below code ?

Code:
var package;
console.log("Package: " + package)
console.log("Amount: " + amount);
  • (A) Package: undefined; An ReferenceError is thrown saying amount is not defined;
  • (B) Package: null; An ReferenceError is thrown saying amount is not defined;
  • (C) Package: undefined; Amount: undefined;
  • (D) Package: null; Amount: null;

A

Admin • 833K Points
Coach

Q. What will be the output of the below code ?

Code:
var i=true;
var j=false;
var k=true;
if( i || J && K){
a=10;
b="True";
}
else {
a=20;
b="False";
}
console.log(a+","+b); 
  • (A) 20,False
  • (B) 20,True
  • (C) 10,False
  • (D) 10,True

A

Admin • 833K Points
Coach

Q. The statement is an example of:

Code:
while (3==3) {}
  • (A) A typographical error
  • (B) An infinite loop
  • (C) An illegal JavaScript statement
  • (D) None of the above

A

Admin • 833K Points
Coach

Q. Which of the following is a syntactically correct for loop?

  • (A) for (i=0;i<=10)
  • (B) for (i=0;i<=10;i++)
  • (C) for i=1 to 10
  • (D) for (i<=10;i++)