JavaScript MCQs – Multiple Choice Questions and Answers – Part 3
Multiple choice questions and answers (MCQs) on JavaScript to prepare for exams, tests, and certifications. These questions are taken from a real written exam and some parts are taken from an interview. So you will find questions on basic techniques such as variables, functions, loops, objects, and more. This quiz will easily prepare anyone to pass their online test.
1. How to declare an array of 10 elements in JavaScript?
A arr = new Array(10)
B var arr[10]
C var arr = array(10)
D var arr(10)
2. How to get a random number between 5 and 9 inclusive?
A Math.floor((Math.random() * 5) + 4);
B Math.floor((Math.random() * 4) + 4);
C Math.floor((Math.random() * 4) + 5);
D Math.floor((Math.random() * 5) + 5);
3. To check if three variables are equal, we are going to use_____?
A X = Y = Z
B (X == B) && (Y == Z)
C (X = B) && (Y = Z)
D (X == B) & (Y == Z)
4. How many parameters can be passed to a function?
A Any
B As much as you want
C One for each argument
D One argument
5. Which of these parameters is not valid?
A text
B a variable
C an operator
D a number
6. How to detect the name of the client’s browser?
A navigator.appName
B browser.name
C client.navName
D window.appName
7. If str = "VWXYZ"
, what returns str.charAt(3)
?
A X
B Y
C Z
D false
8. The following statement A ? B : C
is equivalent to ______?
A if (A) {B; C}
B if (A != B) C
C if (A == B) C
D if (A) {B} else {C}
9. Which one is not a comparison operator?
A <
B >
C =
D !=
10. Which event is specific to the keyboard?
A onkeypress
B onkeydown
C onclick
D onfocus