JavaScript MCQs – Introduction to JavaScript

If you’re preparing for a JavaScript interview, practicing multiple-choice questions (MCQs) is a great way to learn the basics. “Introduction to JavaScript” MCQs focus on important topics like variables, data types, functions, and how JavaScript works with web pages. By solving these questions, you can better understand how JavaScript works and feel more confident during interviews. Whether you’re just starting out or revising for a job, these MCQs can help you prepare effectively.

1.) What is JavaScript primarily used for?

A) Server-side programming
B) Designing static websites
C) Adding interactivity to web pages
D) Writing system-level software

Answer: C

Explanation: JavaScript is primarily used to make web pages interactive by adding dynamic content, event handling, and animations.

2.) Which of the following is a correct way to write JavaScript in an HTML document?

A) <script href=”script.js”></script>
B) <javascript src=”script.js”></javascript>
C) <script src=”script.js”></script>
D) <script-link src=”script.js”></script-link>

Answer: Option C

Explanation: The<script>tag with the src attribute is used to include external JavaScript files in an HTML document.

3.) JavaScript is a ____________ language.

A) Compiled
B) Interpreted
C) Assembly-level
D) Low-level

Answer: Option B

Explanation: JavaScript is an interpreted language, meaning it is executed line-by-line by the browser’s JavaScript engine.

4.) Which company developed JavaScript?

A) Microsoft
B) Sun Microsystems
C) Netscape
D) Google

Answer: Option C

Explanation: JavaScript was developed by Netscape in 1995, originally named Mocha, then LiveScript, and finally JavaScript.

5.) Which of the following is not a JavaScript data type?

A) String
B) Number
C) Boolean
D) Float

Answer: Option D

Explanation: JavaScript has the data type Number, which covers both integers and floating-point numbers, but there is no separate Float data type.

6.) How can you write a comment in JavaScript?

A) /$ This is a comment $/
B) < !– This is a comment –>
C) This is a comment
D) /* This is a comment */

Answer: Option D

Explanation: In JavaScript, single-line comments are written using //, and multi-line comments are written using /* */

7.) What is the correct syntax to display an alert box in JavaScript?

A) alertBox(“Hello”);
B) alert(“Hello”);
C) msg(“Hello”);
D) display(“Hello”);

Answer: Option B

Explanation: The alert() function is used to display an alert box with a specified message.

8.) What is the default value of an uninitialized variable in JavaScript?

A) null
B) undefined
C) 0
D) NaN

Answer: Option B

Explanation: In JavaScript, uninitialized variables have a default value of undefined.

9.) Which of the following is used to declare a variable in JavaScript?

A) var
B) let
C) const
D) All of the above

Answer: Option D

Explanation: JavaScript allows variable declaration using var (old way), let (block-scoped), and const (for constants).

10.) JavaScript is ________________.

A) Case-insensitive
B) Case-sensitive
C) Not case-sensitive for variables
D) Case-sensitive for keywords only

Answer: Option B

Explanation: JavaScript is case-sensitive. Variable names and function names must match their cases exactly.

Leave a Reply

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