MCQ

JavaScript MCQs – Multiple Choice Questions and Answers – Part 1

Multiple choice questions and answers (MCQs) on JavaScript to prepare for exams, tests, and certifications. These questions are taken from a real written exam and some parts are taken from an interview. So you will find questions on basic techniques such as variables, functions, loops, objects, and more. This quiz will easily prepare anyone to pass their online test.
 

1. In which HTML tag do we put the JavaScript code?

A The js tag

B The javascript tag

C The script tag

D The rel tag

C
Example :

<script>
      //Your first script
</script>

 

 

2. How to call a function named “sum”?

A sum()

B call function sum()

C call sum()

D None of the above

A

 

 

3. What is the correct syntax for referring to an external script called “myscript.js”?

A <script href="myscript.js">

B <script name="myscript.js">

C <script src="myscript.js">

D All the answers are true

C

 

 

4. The external JavaScript file must contain the <script> tag?.

A True

B False

B

 

 

5. Where is the right place to insert JavaScript code?

A <head> section

B The two sections <head> and <body> are correct

C <body> section

D None of the above

B

 

 

6. How do you write “Hello World” in an alert box?

A msg("Hello World");

B alert("Hello World");

C msgBox("Hello World");

D alertBox("Hello World");

B

 

 

7. How to write an IF condition in JavaScript?

A if a = 2 then

B if a = 2

C if a == 2 else

D if (a == 2)

D

 

 

8. How to write an IF condition to check if “a” is NOT equal to 2?

A if a <> 2

B if (a != 2)

C if a =! 2 then

D if (a <> 2)

B

 

 

9. How to create a function in JavaScript?

A function f()

B function = f()

C function:f()

D None of the above

A

 

 

10. What is the correct syntax for checking the value of “c”?

A if (c == "XYZ") then { } else { }

B if (c = "XYZ") then { } else { }

C if (c == "XYZ") { } else { }

D if (c = "XYZ") { } else { }

C

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

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