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
The
### Syntax:
### Parameters:
1. callback: A function to execute on each element in the array, taking three arguments:
- element: The current element being processed in the array.
- index (optional): The index of the current element being processed in the array.
- array (optional): The array
2. thisArg (optional): An object to use as
### Example:
In this example, the
findIndex method in JavaScript is used to find the index of the first element in an array that satisfies a provided testing function. If no elements satisfy the testing function, findIndex returns -1. ### Syntax:
array.findIndex(callback(element, index, array), thisArg);
### Parameters:
1. callback: A function to execute on each element in the array, taking three arguments:
- element: The current element being processed in the array.
- index (optional): The index of the current element being processed in the array.
- array (optional): The array
findIndex was called upon. 2. thisArg (optional): An object to use as
this when executing the callback. ### Example:
const numbers = [4, 9, 16, 25, 29];
const isLargeNumber = (element) => element > 18;
const index = numbers.findIndex(isLargeNumber);
console.log(index); // Output: 3
In this example, the
findIndex method returns 3 because 25 is the first element in the array that is greater than 18, and its index is 3. If no element greater than 18 was found, the method would have returned -1.๐1