Home

JavaScript 1000+ MCQ with answer for RRB Group D

Thursday 9th of March 2023

Sharing is caring

1. 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
2. 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
3. Which of the following is not considered as an error in JavaScript?
A. Syntax error
B. Missing of semicolons
C. Division by zero
D. Missing of Bracket
Answer : C
4. 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
5. What will be the output of the following JavaScript code?

A. 125
B. 25
C. 5
D. Error
Answer : C
6. Which keyword is used to define the function in javascript?
A. void
B. int
C. function
D. main
Answer : C
7. 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
8. 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
9. 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
10. 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
11. 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
12. 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
13. 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
14. 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
15. 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
16. Do functions in JavaScript necessarily return a value?
A. It is mandatory
B. Not necessary
C. Few functions return values by default
D. some functions do not return any value
Answer : C
17. What will be the output of the following JavaScript code?
function output(option)
{
return (option ? yes : no);
}
bool ans=true;
console.log(output(ans));

A. Yes
B. No
C. Runtime error
D. Compilation error
Answer : A
18. A linkage of series of prototype objects is called as ________
A prototype stack
B. prototype chain
C. prototype class
D. prototypes
Answer : B
19. 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
20. What will be the output of the following JavaScript code?

A. 1.01
B. 1.047
C. 1.00
D. 1.4
Answer : B
21. 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
22. Consider the following code snippet :
var string2Num=parseInt(123xyz);

The result for the above code snippet would be :

A. 123
B. 123xyz
C. Exception
D. NaN
Answer : A
23. 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
24. The method or operator used to identify the array is __________
A. isarrayType()
B. ==
C. ===
D. typeof
Answer : D
25. 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
26. 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
27. 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
28. 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
29. 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
30. 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
31. The pop() method of the array does which of the following task?
A. decrements the total length by 1
B. increments the total length by 1
C. prints the first element but no effect on the length
D. updates the element
Answer : A
32. When an empty statement is encountered, a JavaScript interpreter __________
A. Ignores the statement
B. Prompts to complete the statement
C. Throws an error
D. Shows a warning
Answer : A
33. Consider the following code snippet :
var grand_Total=eval(10*10+5);

The output for the above statement would be :

A. 10*10+5
B. 105 as a string
C. 105 as an integer value
D. Exception is thrown
Answer : C
34. What will be the output of the following JavaScript code?
function output(object)
{
var place=object ? object.place : Italy;
return clean:+ place;
}
console.log(output({place:India}));

A. clean:India
B. clean:Italy
C. error
D. undefined
Answer : A
35. 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
36. When an empty statement is encountered, a JavaScript interpreter __________
A. Ignores the statement
B. Prompts to complete the statement
C. Throws an error
D. Shows a warning
Answer : A
37. 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
38. 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
39. What is the observation made in the following JavaScript code?
var count = [1,,3];

A. The omitted value takes undefined
B. This results in an error
C. This results in an exception
D. The omitted value takes an integer value
Answer : A
40. 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
41. 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
42. What kind of expression is new Point(2,3)?
A. Primary Expression
B. Object Creation Expression
C. Invocation Expression
D. Constructor Calling Expression
Answer : B
43. What will be the output of the following JavaScript code?
const object1 = {};
a = Symbol('a');
b = Symbol.for('b');
object1[a] = 'harry';
object1[b] = 'derry';
const objectSymbols = Object.getOwnPropertySymbols(object1);
console.log(objectSymbols.length);

A. 0
B. 2
C. 1
D. Error
Answer : B
44. 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
45. The script tag must be placed in __________
A. the head tag
B. the head or body
C. the title or head
D. after the body tag
Answer : B
46. 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
47. 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
48. What will be the output of the following JavaScript code?
function info()
{
int a=1;
int b=2;
return a*b;
}
document.write(info());

A. 1
B. 2
C. 3
D. error
Answer : B
49. 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
50. What will be the output of the following JavaScript code?
int a==2;
int b=4;
int ans=a+b;
print(ans);

A. 2
B. 6
C. 0
D. error
Answer : D

Sharing is caring