JavaScript MCQ Questions and Answers

JavaScript MCQ Questions and Answers Here provide JavaScript MCQ (Multiple Choice Questions) with Answers. you can learn and practice JavaScript MCQ Questions.

1. What is JavaScript?

A) JavaScript is a scripting language used to make the website interactive
B) JavaScript is an assembly language used to make the website interactive
C) JavaScript is a compiled language used to make the website interactive
D) None of the mentioned

Answer: A
Explanation: JavaScript is a scripting language used along with HTML and CSS to make the website interactive along. It is used both on the client-side and server-side.


2) Which of the following is correct about JavaScript?

A) JavaScript is an Object-Based language
B) JavaScript is Assembly-language
C) JavaScript is an Object-Oriented language
D) JavaScript is a High-level language

Answer: A
Explanation: JavaScript is a scripting language used along with HTML and CSS to make the website interactive along. It is used both on the client-side and server-side.


3) Among the given statements, which statement defines closures in JavaScript?

A) JavaScript is a function that is enclosed with references to its inner function scope
B) JavaScript is a function that is enclosed with references to its lexical environment
C) JavaScript is a function that is enclosed with the object to its inner function scope
D) None of the mentioned

Answer: B
Explanation: A closure is a function that is enclosed with references to its lexical environment. A closure allows an inner function to access the scope of an outside function. Closures are formed every time a function is created in JavaScript, during function creation time.


4) What will be the output of the following JavaScript code snippet?

<p id="demo"></p>
var txt1 = "Study2Online_";
var txt2 = "Javascriptmcq";
document.getElementById("demo").innerHTML = txt1 + txt2;

A) error
B) Study2Online_ Javascriptmcq
C) undefined
D) Study2Online_Javascriptmcq

Answer: D
Explanation: The + operator in javascript acts as a concatenation operator when used with string. The new string does not have any space between the two added strings.


5) What will be the output of the following JavaScript code?

<p id="demo"></p>
<script>
var js = 10;
js *= 5;
document.getElementById("demo").innerHTML = js;
</script>

A) 10
B) 50
C) 5
D) Error

Answer: B
Explanation: The *= operator in javascript is a shorthand expression for the multiplication of a particular number. It is a combination of two operators * and = .


6) Arrays in JavaScript are defined by which of the following statements?

A) It is an ordered list of values
B) It is an ordered list of objects
C) It is an ordered list of string
D) It is an ordered list of functions

Answer: A
Explanation: An array in JavaScript is an ordered list of values, each value is referred to as an element, and it is identified by an index. An array can include values of many sorts and the length of an array dynamically sized.


7) What will be the output of the following JavaScript code?

// JavaScript Comparison Operators
function compare()
{
    let a=2;
    let b=2.0;
    if(a==b)
        return true;
    else
        return false;
}

A) false
B) true
C) compilation error
D) runtime error

Answer: B
Explanation: The == in JS convert different types of operands to the same type before making the comparison whereas a strict comparison === results in true value if the operands are of the same type and the contents match.


8) What will be the output of the following JavaScript code snippet?

// JavaScript Equalto Operators
function equalto()
{
    let num=10;
    if(num==="10")
        return true;
    else
        return false;
}

A) false
B) true
C) compilation error
D) runtime error

Answer: A
Explanation: A === operator in JS is only true if the operands are of the same type and the contents match. Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions. In this case, we are comparing an integer and a string so it will be false.


9) Will the following JavaScript code work?

var js = (function(x) {return x*x;}(10));

A) Exception will be thrown
B) Memory leak
C) Error
D) Yes, perfectly

Answer: D
Explanation: For functions expressed as expressions, the function name is optional in Javascript. Sometimes function expressions are defined and used right away.


10) Which of the following is not javascript data types?

A) Null type
B) Undefined type
C) Number type
D) All of the mentioned

Answer: D
Explanation: JavaScript is a dynamic, loosely typed language. Variables in JavaScript aren’t tied to any specific value type, and each variable can be assigned and reassigned to values of all the types.

Be the first to comment

Leave a Reply

Your email address will not be published.


*