Home

1000+ JavaScript Multiple Choice Question Answer [Solved]

Thursday 9th of March 2023

Sharing is caring

1. What will be the output of the following JavaScript code?
string a = hi;
string b =there;
alert(a+b);

A. hi
B. there
C. hithere
D. undefined
Answer : C
2. Which attribute is used to specify that the script is executed when the page has finished parsing? (only for external scripts)
A. parse
B. a sync
C. defer
D. type
Answer : C
3. Consider the following code snippet :
var tensquared = (function(x) {return x*x;}(10));

Will the above code work ?

A. Yes, perfectly
B. Error
C. Exception will be thrown
D. Memory leak
Answer : A
4. What will happen if a return statement does not have an associated expression?
A. It returns the value 0
B. It will throw an exception
C. It returns the undefined value
D. It will throw an error
Answer : C
5. What is a block statement in JavaScript?
A. conditional block
B. block that contains a single statement
C. both conditional block and a single statement
D. block that combines multiple statements into a single compound statement
Answer : D
6. What will be the output of the following Javascript code?
int size=5;
int a=5;
int size=4;
for(int j=size;j>=0;j--)
{
console.log(a);
a=a-2;
}

A. 5555
B. 5321
C. 531-1
D. 531
Answer : C
7. What happens in the following javaScript code snippet?
var count = 0;
while (count < 10)
{
console.log(count);
count++;
}

A. The values of count are logged or stored in a particular location or storage
B. The value of count from 0 to 9 is displayed in the console
C. An error is displayed
D. An exception is thrown
Answer : B
8. A function with no return value is called ___________
A. Procedures
B. Method
C. Static function
D. Dynamic function
Answer : A
9. What will be the output of the following Javascript code?
var arr = [7, 5, 9, 1];
var min = Math.min.apply(null, arr);
document.writeln(min);

A. 7
B. 5
C. 1
D. 9
Answer : C
10. If you have a function f and an object o, you can define a method named m of o with
A. o.m=m.f;
B. o.m=f;
C. o=f.m;
D. o=f;
Answer : B
11. Which of the operator is used to test if a particular property exists or not?
A. in
B. exist
C. within
D. exists
Answer : A
12. What will be the output of the following JavaScript code?
var arr=[1,2,3];
var rev=arr.reverse();
document.writeln(rev);

A. 1, 2, 3
B. 3, 2, 1
C. 3
D. 1
Answer : B
13. What will be the output of the following JavaScript code?
var a=5 , b=1
var obj = { a : 10 }
with(obj)
{
alert(b)
}

A. 10
B. Error
C. 1
D. 5
Answer : C
14. The reduce and reduceRight methods follow a common operation called __________
A. filter and fold
B. inject and fold
C. finger and fold
D. fold
Answer : B
15. What is a block statement in JavaScript?
A. conditional block
B. block that contains a single statement
C. both conditional block and a single statement
D. block that combines multiple statements into a single compound statement
Answer : D
16. What will be the equivalent code of the following JavaScript code?
o.m(x,y);

A. o.m(x) && o.m(y);
B. o[m](x,y);
C. o(m)[x,y];
D. o.m(x && y);
Answer : B
17. The unordered collection of properties, each of which has a name and a value is called _________
A. String
B. Object
C. Serialized Object
D. Array
Answer : B
18. What will be the output of the following Javascript code?
var a=3.7;
var b=2;
a=ciel(a)
document.writeIn(a*b);

A. 6
B. 7.4
C. 7.5
D. 8
Answer : D
19. A conditional expression is also called a _______________
A. Alternative to if-else
B. Immediate if
C. If-then-else statement
D. Switch statement
Answer : B
20. Consider the following JavaScript statements.
var text = testing: 1, 2, 3; // Sample text
var pattern = /d+/g // Matches all instances of one or more digits

In order to check if the pattern matches with the string text, the statement is ____________

A. text==pattern
B. text.equals(pattern)
C. text.test(pattern)
D. pattern.test(text)
Answer : D
21. The type of a variable that is volatile is _______________
A. Volatile variable
B. Mutable variable
C. Immutable variable
D. Dynamic variable
Answer : B
22. Among the keywords below, which one is not a statement?
A. debugger
B. with
C. if
D. use strict
Answer : D
23. Consider the following code snippet.
for(var p in o)
console.log(o[p]);

The above code is equivalent to which code?

A.
for (var i = 0;i < a.length;i++)
console.log(a[i]);

B.
for (int i = 0;i < a.length;i++)
console.log(a[i]);

C.
for (var i = 0;i <= a.length;i++)
console.log(a[i]);

D.
for (var i = 1;i < a.length;i++)
console.log(a[i]);

Answer : A
24. What will be the output of the following Javascript code?
var txt1 = good;
var txt2 = day;
document.getElementById(demo).innerHTML = txt1 + txt2;

 


A. good day
B. goodday
C. error
D. undefined
Answer : B
25. The purpose of extensible attribute is to __________
A. make all of the own properties of that object non configurable
B. to configure and bring a writable property
C. lock down objects into a known state and prevent outside tampering
D. to include new properties into the object
Answer : C
26. Which keyword is used to define the function in javascript?
A. void
B. int
C. function
D. main
Answer : C
27. JavaScript _________ when there is an indefinite or an infinite value during an arithmetic computation.
A. Prints an exception error
B. Prints an overflow error
C. Displays Infinity
D. Prints the value as such
Answer : C
28. What will be the output of the following JavaScript code?
const object1 = {
property1: 20
};
console.log(Object.is(object1));

A. 20
B. true
C. false
D. error
Answer : C
29. What will be the equivalent output of the following JavaScript code snippet?
x = ~-y;
w = x = y = z;
q = a?b:c?d:e?f:g;

A.
x = ~(-y); w = (x = (y = z));
q = a?b:(c?d:(e?f:g));

B.
x = a?b:(c?d:(e?f:g));
q = ~(-y); w = (x = (y = z));

C.
x = (x = (y = z));w = ~(-y);
q = a?b:(c?d:(e?f:g));

D.
x = ~(-y); w = (x = (y = z));
q = (c?d:(e?f:g));

Answer : A
30. What will be the output of the following JavaScript code?

A. 125
B. 25
C. 5
D. Error
Answer : C
31. What will be the output of the following Javascript code?
<script>
txt1 = “ one”;
txt1 += “two”;
document.getElementById("demo").innerHTML = txt1;
</script>



A. onetwo
B. one two
C. error
D. undefined
Answer : A
32. What will be the output of the following JavaScript code?
function height()
{
var height = 123.56;
var type = (height>=190) ? tall : short;
return type;
}

A. 123.56
B. 190
C. tall
D. short
Answer : D
33. In the following switch syntax, the expression is compared with the case labels using which of the following operator(s)?
switch(expression)
{
statements
}

A. ==
B. equals
C. equal
D. ===
Answer : D
34. What will be the output of the following JavaScript code?

A. 1.01
B. 1.047
C. 1.00
D. 1.4
Answer : B
35. What will be the output of the following JavaScript code?
var val1=[1,2,3];
var val2=[6,7,8];
var result=val1.concat(val2);
document.writeln(result);

A. 1, 2, 3
B. Error
C. 1, 2, 3, 6, 7, 8
D. 123
Answer : C
36. The statement a===b refers to _________
A. Both a and b are equal in value, type and reference address
B. Both a and b are equal in value
C. Both a and b are equal in value and type
D. There is no such statement
Answer : C
37. Consider the following code snippet.
for(var p in o)
console.log(o[p]);

The above code is equivalent to which code?

A.
for (var i = 0;i < a.length;i++)
console.log(a[i]);

B.
for (int i = 0;i < a.length;i++)
console.log(a[i]);

C.
for (var i = 0;i <= a.length;i++)
console.log(a[i]);

D.
for (var i = 1;i < a.length;i++)
console.log(a[i]);

Answer : A
38. Assume that we have to convert false that is a non-string to string. The command that we use is (without invoking the new operator).
A. false.toString()
B. String(false)
C. String newvariable=false
D. Both false.toString() and String(false)
Answer : D
39. Consider the following code snippet
function f(o)
{
if (o === undefined) debugger;
}

What could be the task of the statement debugger?

A. It does nothing but a simple breakpoint
B. It debugs the error in that statement and restarts the statements execution
C. It is used as a keyword that debugs the entire program at once
D. It is used to find error in the statement
Answer : A
40. What will be the output of the following JavaScript code?
function printprops(o)
{
for(var p in o)
console.log(p + : + o[p] +
);
}

A. Prints the contents of each property of o
B. Returns undefined
C. Prints only one property
D. Prints the address of elements
Answer : B
41. What will be the output of the following JavaScript code?
function code(id,name)
{
this.id = id;
this.name = name;
}
function pcode(id,name)
{
code.call(this,id,name);
}
document.writeln(new pcode(101,vivek).id);

A. vivek
B. 101
C. Runtime error
D. Compilation error
Answer : B
42. JavaScript can be written __________
A. directly into JS file and included into HTML
B. directly on the server page
C. directly into HTML pages
D. directly into the css file
Answer : A
43. What will be the possible output of the following JavaScript code?
var a = [1,2,3,4,5];
a.slice(0,3);

A. Returns [1,2,3]
B. Returns [4,5]
C. Returns [1,2,3,4]
D. Returns [1,2,3,4,5]
Answer : C
44. The var and function are __________
A. Keywords
B. Declaration statements
C. Data types
D. Prototypes
Answer : B
45. One of the special feature of an interpreter in reference with the for loop is that ___________
A. Before each iteration, the interpreter evaluates the variable expression and assigns the name of the property
B. The iterations can be infinite when an interpreter is used
C. The body of the loop is executed only once
D. the iteration is finite when an interpreter is used
Answer : A
46. The expression of calling (or executing) a function or method in JavaScript is called ________
A. Primary expression
B. Functional expression
C. Invocation expression
D. Property Access Expression
Answer : C
47. The primary purpose of the array map() function is that it __________
A. maps the elements of another array into itself
B. passes each element of the array and returns the necessary mapped elements
C. passes each element of the array on which it is invoked to the function you specify, and returns an array containing the values returned by that function
D. pass the elements of the array into another array
Answer : C
48. What will be the output of the following Javascript code?
var add=new Function(num1,num2,return num1+num2);
document.writeln(add(2,5));

A. 2
B. 5
C. Error
D. 7
Answer : D
49. The function stops its execution when it encounters?
A. continue statement
B. break statement
C. goto statement
D. return statement
Answer : D
50. Which is a more efficient JavaScript code snippet?
Code 1 :
for(var num=10;num>=1;num--)
{
document.writeln(num);
}

Code 2 :
var num=10;
while(num>=1)
{
document.writeln(num);
num++;
}

A. Code 1
B. Code 2
C. Both Code 1 and Code 2
D. Cannot Compare
Answer :
A

Sharing is caring