JavaScript MCQs – Introduction to JavaScript

11.) Which symbol is used to assign a value to a variable in JavaScript?

A) :
B) =
C) ==
D) ===

Answer: Option B

Explanation: The = symbol is used for assignment in JavaScript.

12.) Which keyword is used to define a constant in JavaScript?

A) const
B) let
C) var
D) constant

Answer: Option A

Explanation: The const keyword is used to declare constants in JavaScript.

13.) Which function is used to parse a string to an integer in JavaScript?

A) parseInt()
B) parseInteger()
C) getInt()
D) parse()

Answer: Option A

Explanation: The parseInt() function is used to parse a string and convert it to an integer.

14.) Which method can be used to find the length of a string in JavaScript?

A) str.length()
B) str.size
C) str.length
D) str.size()

Answer: Option C

Explanation: The length property is used to find the length of a string in JavaScript.

15.) What does NaN mean in JavaScript?

A) Not a Null
B) Not a Name
C) Not a Number
D) None of the above

Answer: Option C

Explanation: NaN stands for “Not a Number” and is returned when an operation cannot produce a valid number.

16.) Which statement is used to stop the execution of a loop in JavaScript?

A) break
B) exit
C) stop
D) return

Answer: Option A

Explanation: The break statement is used to exit a loop prematurely in JavaScript.

17.) What does ‘typeof’ operator do in JavaScript?

A) Checks variable type and compares it.
B) Checks the data type of a value.
C) Converts one type to another.
D) Checks if a variable exists.

Answer: Option B

Explanation: The typeof operator is used to determine the data type of a given value.

18.) Which of the following is a JavaScript framework/library?

A) React
B) Django
C) Laravel
D) Flask

Answer: Option A

Explanation: React is a popular JavaScript library for building user interfaces, while the others are frameworks for other languages.

19.) What is the output of console.log(typeof null);?

A) “null”
B) “object”
C) “undefined”
D) “NaN”

Answer: Option B

Explanation: Due to a historical bug, typeof null returns “object”, although null is not an object.

20.) Which operator is used to compare both value and type in JavaScript?

A) ==
B) !=
C) ===
D) !==

Answer: Option C

Explanation: The === operator checks for both value and type equality in JavaScript.

Leave a Reply

Your email address will not be published. Required fields are marked *