codebypc
2.09K subscribers
210 photos
59 videos
160 files
250 links
Html, css3, javascript, reactjs, express, Fullstack, backend, Bootstrap, mongodb
Download Telegram
๐Ÿฅฐ3
๐Ÿ‘1
๐Ÿ‘2๐Ÿ”ฅ1
๐Ÿ”ฅ1
10 JavaScript MCQs
### 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
100+ JavaScript projects ๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡ for beginners to advanced..
๐Ÿ‘2
codebypc pinned ยซhttps://www.100jsprojects.com/ยป
๐Ÿ‘1
๐Ÿ‘1
๐Ÿ‘1
๐Ÿ‘1
๐Ÿ‘2
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