Home

JavaScript 1000+ MCQ with answer for GRE

Thursday 9th of March 2023

Sharing is caring

1. 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
2. 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
3. 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
4. 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
5. 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
6. JavaScript Code can be called by using ____________
A. RMI
B. Triggering Event
C. Preprocessor
D. Function/Method
Answer : D
7. Which keyword is used to define the function in javascript?
A. void
B. int
C. function
D. main
Answer : C
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. 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
10. 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
11. What will be the shift() output of the following JavaScript code?
var a = [];
a.unshift(1);
a.unshift(22);
a.shift();
a.unshift(3,[4,5]);
a.shift();
a.shift();
a.shift();

A. 1
B. [4,5]
C. [3,4,5]
D. Exception is thrown
Answer : A
12. 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
13. What will happen if the body of a for/in loop deletes a property that has not yet been enumerated?
A. The property will be stored in a cache
B. The loop will not run
C. That property will not be enumerated
D. The property will be enumerated
Answer : C
14. 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
15. 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
16. 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 contine keyword breaks out of the loop
Answer : C
17. Among the keywords below, which one is not a statement?
A. debugger
B. with
C. if
D. use strict
Answer : D
18. What will be the output of the following JavaScript code?
var arr = [7, 5, 9, 1];
var value = Math.max.apply(null, arr);
document.writeln(value);

A. 7
B. 5
C. 1
D. 9
Answer : D
19. What is the prototype represents in the following JavaScript code snippet?
function f() {};

A. Function f
B. A custom constructor
C. Prototype of a function
D. Not valid
Answer : B
20. 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
21. What will be the output of the following JavaScript code?
var grade='E';
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. 0
C. 18
D. 17
Answer : B
22. What will be the output of the following JavaScript code?
int a=1;
if(a!=null)
return 1;
else
return 0;

A. 1
B. 0
C. runtime error
D. compiler error
Answer : A
23. The type of a variable that is volatile is _______________
A. Volatile variable
B. Mutable variable
C. Immutable variable
D. Dynamic variable
Answer : B
24. 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
25. What are the three important manipulations done in a for loop on a loop variable?
A. Updation, Incrementation, Initialization
B. Initialization,Testing, Updation
C. Testing, Updation, Testing
D. Initialization,Testing, Incrementation
Answer : B
26. 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
27. 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
28. Consider the following code snippet :
function constfuncs()
{
var funcs = [];
for(var i = 0; i < 10; i++)
funcs[i] = function() { return i; };
return funcs;
}
var funcs = constfuncs();
funcs[5]()

What does the last statement return ?

A. 9
B. 0
C. 10
D. None of the mentioned
Answer : C
29. What will be the output of the following JavaScript code?

A. 1.01
B. 1.047
C. 1.00
D. 1.4
Answer : B
30. What will be the output of the following JavaScript code?
var values=[one,two,Three];
var ans=values.shift();
document.writeln(ans);

A. one
B. two
C. three
D. error
Answer : A
31. What will be the output of the following JavaScript code?
const obj1 = { property1: '10'};
const obj2 = Object.freeze(obj1);
obj2.property1 = '20';
console.log(obj2.property1);

A. 10
B. 20
C. Runtime error
D. Compilation error
Answer : A
32. 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
33. A proper scripting language is a __________
A. High level programming language
B. Assembly level programming language
C. Machine level programming language
D. Low level programming language
Answer : A
34. 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
35. 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
36. Among the keywords below, which one is not a statement?
A. debugger
B. with
C. if
D. use strict
Answer : D
37. 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
38. 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
39. An expression that can legally appear on the left side of an assignment expression. is a well known explanation for variables, properties of objects, and elements of arrays. They are called ___________
A. Properties
B. Prototypes
C. Lvalue
D. Definition
Answer : C
40. 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
41. A function with no return value is called ___________
A. Procedures
B. Method
C. Static function
D. Dynamic function
Answer : A
42. 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
43. The snippet that has to be used to check if a is not equal to null is _________
A. if(a!=null)
B. if (!a)
C. if(a!null)
D. if(a!==null)
Answer : D
44. The main purpose of a Live Wire in NetScape is to ________
A. Create linkage between client side and server side
B. Permit server side, JavaScript code, to connect to RDBMS
C. Support only non relational database
D. To interpret JavaScript code
Answer : B
45. 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
46. 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
47. The basic purpose of the toLocaleString() is to _________
A. return a localised object representation
B. return a parsed string
C. return a local time in the string format
D. return a localized string representation of the object
Answer : D
48. 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
49. What will be the output of the following Javascript code?
var a= 0;
var b = 0;
while (a < 3)
{
a++;
b += a;
console.log(b);
}

A. 135
B. 123
C. 013
D. 01
Answer : A
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