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?
<script>
var x = 5;
var y = 2;
var z = x % y;
document.getElementById("demo").innerHTML = z;
</script>



A. 0
B. 1
C. 2
D. 5
Answer : B
2. What will be the output of the following JavaScript code?
const obj = {prop: 12};
Object.preventExtensions(obj);
console.log( Object.isExtensible(obj));

A. 12
B. false
C. true
D. error
Answer : B
3. Consider the following code snippet.
while (a != 0)
{
if (a == 1)
continue;
else
a++;
}

What will be the role of the continue keyword in the above code snippet?

A. The continue keyword restarts the loop
B. The continue keyword skips the next iteration
C. The continue keyword skips the rest of the statements in that iteration
D. The continue keyword breaks out of the loop
Answer : C
4. What will be the output of the following Javascript code?
int a=0;
for(a;a<5;a++);
console.log(a);

A. 0
B. error
C. 4
D. 5
Answer : D
5. To determine whether one object is the prototype of (or is part of the prototype chain of) another object, one should use the ____________
A. isPrototypeOf() method
B. equals() method
C. === operator
D. ==opertor
Answer : A
6. The function stops its execution when it encounters?
A. continue statement
B. break statement
C. goto statement
D. return statement
Answer : D
7. When does the function name become optional in JavaScript?
A. When the function is defined as a looping statement
B. When the function is defined as expressions
C. When the function is predefined
D. when the function is called
Answer : B
8. What will be the output of the following JavaScript code?
int a=4;
int b=1;
int c=0;
If(a==b)
document.write(a);
else if(a==c)
document.write(a);
else
document.write(c);

A. 4
B. 1
C. Error
D. 0
Answer : D
9. 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
10. What will be the output of the following Javascript code?
var a = 10;
do {
a += 1;
console.log(a);
} while (a < 5);

A. 11121314
B. 1112
C. 12345
D. 11
Answer : D
11. What will be the step of the interpreter in a jump statement when an exception is thrown?
A. The interpreter stops its work
B. The interpreter throws another exception
C. The interpreter jumps to the nearest enclosing exception handler
D. The interpreter throws an error
Answer : C
12. Consider the following code snippet :
var c = counter(), d = counter();
c.count()
d.count()
c.reset()
c.count()
d.count()

The state stored in d is :

A. 1
B. 0
C. Null
D. Undefined
Answer : A
13. JavaScript Code can be called by using ____________
A. RMI
B. Triggering Event
C. Preprocessor
D. Function/Method
Answer : D
14. What will be the output of the following JavaScript code?
function compare()
{
int num=2;
char b=2;
if(a==b)
return true;
else
return false;
}

A. true
B. false
C. runtime error
D. compilation error
Answer : A
15. The enumeration order becomes implementation dependent and non-interoperable if ___________
A. If the object inherits enumerable properties
B. The object does not have the properties present in the integer array indices
C. The delete keyword is never used
D. Object.defineProperty() is not used
Answer : A
16. For the below mentioned code snippet:
var o = new Object();

The equivalent statement is:

A. var o = Object();
B. var o;
C. var o= new Object;
D. Object o=new Object();
Answer : C
17. 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
18. In the following syntax, the data type within the square brackets must be ___________
book[datatype]=assignment_value;

A. An integer
B. A String
C. An object
D. Floating point
Answer : B
19. JavaScript Code can be called by using ___________
A. RMI
B. Triggering Event
C. Preprocessor
D. Function/Method
Answer : D
20. 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
21. The enumeration order becomes implementation dependent and non-interoperable if ___________
A. If the object inherits enumerable properties
B. The object does not have the properties present in the integer array indices
C. The delete keyword is never used
D. Object.defineProperty() is not used
Answer : A
22. The object has three object attributes namely ________
A. Class, parameters, objects extensible flag
B. Prototype, class, objects parameters
C. Prototype, class, objects extensible flag
D. Native object, Classes and Interfaces and Objects extensible flag
Answer : C
23. 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
24. The function definitions in JavaScript begins with _____________
A. Identifier and Parentheses
B. Return type and Identifier
C. Return type, Function keyword, Identifier and Parentheses
D. Identifier and Return type
Answer : C
25. What will the following code snippet work? If not, what will be the error?
function tail(o)
{
for (; o.next; o = o.next) ;
return o;
}

A. No, this will throw an exception as only numerics can be used in a for loop
B. No, this will not iterate
C. Yes, this will work
D. No, this will result in a runtime error with the message Cannot use Linked List
Answer : C
26. A function definition expression can be called as __________
A. Function prototype
B. Function literal
C. Function calling
D. Function declaration
Answer : B
27. What will be the output of the following JavaScript code?
function compare()
{
int a=1;
char b=1;
if(a.tostring()===b)
return true;
else
return false;
}

A. true
B. false
C. runtime error
D. logical error
Answer : A
28. What will be the firstname and surname of the following JavaScript code?
var book = {
main title: JavaScript,
'sub-title': The Definitive Guide,
for: all audiences,
author: {
firstname: David,
surname: Flanagan
}
};

A. properties
B. property values
C. property names
D. objects
Answer : C
29. What will be the output of the following JavaScript code?
var string1 = 123;
var intvalue = 123;
alert( string1 + intvalue );

A. 123246
B. 246
C. 123123
D. Exception
Answer : C
30. A hexadecimal literal begins with __________
A. 00
B. 0x
C. 0X
D. Both 0x and 0X
Answer : D
31. What will the following code snippet work? If not, what will be the error?
function tail(o)
{
for (; o.next; o = o.next) ;
return o;
}

A. No, this will throw an exception as only numerics can be used in a for loop
B. No, this will not iterate
C. Yes, this will work
D. No, this will result in a runtime error with the message Cannot use Linked List
Answer : C
32. The property of a primary expression is ____________
A. stand-alone expressions
B. basic expressions containing all necessary functions
C. contains variable references alone
D. contains only keywords
Answer : A
33. 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 single compound statement
Answer : D
34. What will be the output of the following JavaScript code?
Int a=1;
if(a>10)
{
document.write(10);
}
else
{
document.write(a);
}

A. 10
B. 0
C. 1
D. Undefined
Answer : C
35. What will be the output of the following Javascript code?
function range(int length)
{
int a=5;
for(int i=0;i<length;i++)
{
console.log(a);
}
}
range(3);

A. 5
B. 555
C. 3
D. error
Answer : B
36. Consider the following code snippet.
function printArray(a)
{
var len = a.length, i = 0;
if (len == 0)
console.log(Empty Array);
else
{
do
{
console.log(a[i]);
} while (++i < len);
}
}

What does the above code result?

A. Prints the numbers in the array in order
B. Prints the numbers in the array in the reverse order
C. Prints 0 to the length of the array
D. Prints Empty Array
Answer : A
37. Which of the following Attribute is used to include External JS code inside your HTML Document?
A. src
B. ext
C. script
D. link
Answer : A
38. JavaScript is ideal to ________
A. make computations in HTML simpler
B. minimize storage requirements on the web server
C. increase the download time for the client
D. increase the loading time of the website
Answer : B
39. What will be the output of the following Javascript code?
<script>
document.getElementById("demo").innerHTML = typeof "John"
</script>



A. integer
B. number
C. string
D. error
Answer : C
40. What will be the output of the following JavaScript code?
var grade='A';
var result;
switch(grade)
{
case 'A':
result+=10;
case 'B':
result+= 9;
case 'C':
result+= 8;
default:
result+= 0;
}
document.write(result);

A. 10
B. 27
C. 8
D. 0
Answer : B
41. 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
42. What will happen if reverse() and join() methods are used simultaneously?
A. Reverses and stores in the same array
B. Reverses and concatenates the elements of the array
C. Reverses
D. Stores the elements of an array in normal order
Answer : A
43. What is the difference between the two lines given below ?
!!(obj1 && obj2);
(obj1 && obj2);

A. Both the lines result in a boolean value True
B. Both the lines result in a boolean value False
C. Both the lines checks just for the existence of the object alone
D. The first line results in a real boolean value whereas the second line merely checks for the existence of the objects
Answer : D
44. 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
45. What will be the output of the following JavaScript code?
var a1 = [,,,];
var a2 = new Array(3);
0 in a1
0 in a2

A. true false
B. false true
C. true true
D. false true
Answer : A
46. The generalised syntax for a real number representation is __________
A. [digits][.digits][(E|e)[(+|-)]digits]
B. [digits][+digits][(E|e)[(+|-)]digits]
C. [digits][(E|e)[(+|-)]digits]
D. [.digits][digits][(E|e)[(+|-)]digits]
Answer : A
47. 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
48. What is the purpose of a return statement in a function?
A. Returns the value and continues executing rest of the statements, if any
B. Returns the value and stops the program
C. Returns the value and stops executing the function
D. Stops executing the function and returns the value
Answer : D
49. The var and function are __________
A. Keywords
B. Declaration statements
C. Data types
D. Prototypes
Answer : B
50. What will be the step of the interpreter in a jump statement when an exception is thrown?
A. The interpreter stops itswork
B. The interpreter throws another exception
C. The interpreter jumps to the nearest enclosing exception handler
D. The interpreter throws an error
Answer : C

Sharing is caring