10 JavaScript MCQs
### Question 1:
What is the correct syntax to print a message in the console in JavaScript?
a)
b)
c)
d)
Answer: a)
### Question 2:
Which of the following is not a valid JavaScript variable name?
a)
b)
c)
d)
Answer: a)
### Question 3:
What is the output of
a)
b)
c)
d)
Answer: a)
### Question 4:
Which built-in method removes the last element from an array and returns that element?
a)
b)
c)
d)
Answer: c)
### Question 5:
How do you write a comment in JavaScript?
a)
b)
c)
d) Both b) and c)
Answer: d) Both b) and c)
### Question 6:
Which method is used to create a new array from an existing array with only elements that pass a test provided by a function?
a)
b)
c)
d)
Answer: b)
### Question 7:
What will the following code output?
a)
b)
c)
d)
Answer: b)
### Question 8:
Which of the following is a JavaScript library ?
a)
b)
c)
d)
Answer: c)
### Question 9:
How do you declare a JavaScript variable?
a)
b)
c)
d)
Answer: a)
### Question 10:
Which operator is used to assign a value to a variable in JavaScript?
a)
b)
c)
d)
Answer: b)
### Question 1:
What is the correct syntax to print a message in the console in JavaScript?
a)
console.log("Hello World"); b)
print("Hello World"); c)
echo "Hello World"; d)
console.print("Hello World"); Answer: a)
console.log("Hello World"); ### Question 2:
Which of the following is not a valid JavaScript variable name?
a)
2names b)
_name c)
firstName d)
name2 Answer: a)
2names ### Question 3:
What is the output of
typeof NaN in JavaScript? a)
number b)
undefined c)
NaN d)
object Answer: a)
number ### Question 4:
Which built-in method removes the last element from an array and returns that element?
a)
last() b)
get() c)
pop() d)
None of the above Answer: c)
pop() ### Question 5:
How do you write a comment in JavaScript?
a)
<!-- This is a comment --> b)
// This is a comment c)
/* This is a comment */ d) Both b) and c)
Answer: d) Both b) and c)
### Question 6:
Which method is used to create a new array from an existing array with only elements that pass a test provided by a function?
a)
reduce() b)
filter() c)
map() d)
forEach() Answer: b)
filter() ### Question 7:
What will the following code output?
console.log(0.1 + 0.2 == 0.3); a)
true b)
false c)
undefined d)
NaN Answer: b)
false ### Question 8:
Which of the following is a JavaScript library ?
a)
Django b)
Rails c)
React d)
Laravel Answer: c)
React ### Question 9:
How do you declare a JavaScript variable?
a)
var carName; b)
variable carName; c)
v carName; d)
carName; Answer: a)
var carName; ### Question 10:
Which operator is used to assign a value to a variable in JavaScript?
a)
* b)
= c)
- d)
x Answer: b)
=๐7โค4๐1