Home

RRB ALP - JavaScript 1000+ MCQ [Solved] PDF Download

Thursday 9th of March 2023

Sharing is caring

1. 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
2. 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
3. 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
4. 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
5. 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
6. 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
7. 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
8. A linkage of series of prototype objects is called as ________
A. prototype stack
B. prototype chain
C. prototype class
D. prototypes
Answer : B
9. 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
10. What will be the output of the following JavaScript code?

A. 7.25
B. -7.25
C. 7
D. -7
Answer : A
11. 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
12. 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
13. 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
14. What will be the output of the following Javascript code?
<script>
var x = 10;
x *= 5;
document.getElementById("demo").innerHTML = x;
</script>



A. 5
B. 10
C. 50
D. Error
Answer : C
15. 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
16. 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;br>default:
result+= 0;
}
document.write(result);

A. 10
B. 0
C. 18
D. 17
Answer : B
17. 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
18. 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
19. The one-liner code that concatenates all strings passed into a function is
A.
function concatenate()
{
return String.prototype.concat('', arguments);
}

B.
function concatenate()
{
return String.prototype.apply('', arguments);
}

C.
function concatenate()
{
return String.concat.apply('', arguments);
}

D.
function concatenate()
{
return String.prototype.concat.apply('', arguments);
}

Answer : D
20. 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
21. Among the following, which one is a ternary operator?
A. +
B. :
C. ^
D. ?:
Answer : D
22. 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
23. 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
24. 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
25. 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
26. 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
27. 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
28. 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
29. 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
30. What will be the output of the following JavaScript code?
function equalto()
{
int num=10;
if(num===10)
return true;
else
return false;
}

A. true
B. false
C. runtime error
D. compilation error
Answer : A
31. 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
32. What will be the output of the following JavaScript code?
int sum=0;
var arr = [10,15,20,30];
arr.forEach(function myFunction(element)
{
sum= sum+element;
});
document.writeln(sum);

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

A. 10
B. 9
C. 8
D. 0
Answer : B
34. What will be the output of the following JavaScript code?
var person =
{
name: Rahul,
getName: function()
{
nreturn this.name;
}
}
var unboundName = person.getName;
var boundName = unboundName.bind(person);
document.writeln(boundName());

A. runtime error;
B. compilation error
C. Rahul
D. undefined
Answer : C
35. 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
36. 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
37. 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
38. 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
39. 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
40. The type of a variable that is volatile is _______________
A. Volatile variable
B. Mutable variable
C. Immutable variable
D. Dynamic variable
Answer : B
41. 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
42. 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
43. The escape sequence stands for _________
A. Floating numbers
B. Representation of functions that returns a value
C. is not present in JavaScript
D. Form feed
Answer : D
44. 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
45. 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
46. 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
47. The function stops its execution when it encounters?
A. continue statement
B. break statement
C. goto statement
D. return statement
Answer : D
48. 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
49. 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
50. The var and function are __________
A. Keywords
B. Declaration statements
C. Data types
D. Prototypes
Answer : B

Sharing is caring