Home

JavaScript 1000+ MCQ with answer for RRB NTPC

Thursday 9th of March 2023

Sharing is caring

1. 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
2. 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
3. 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
4. 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
5. 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
6. 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
7. 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
8. 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
9. 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
10. 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
11. 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
12. 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
13. 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
14. 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
/div>
15. 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
16. 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
17. 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
18. The function stops its execution when it encounters?
A. continue statement
B. break statement
C. goto statement
D. return statement
Answer : D
19. 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
20. The web development environment (JavaScript) offers which standard construct for data validation of the input entered by the user.
A. Controlled loop constructs
B. Case checking constructs
C. Validation constructs
D. All of the mentioned
Answer : D
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.
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
23. What will be the output of the following JavaScript code?
var values=[1,2,3,4]
var ans=values.slice(1);
document.writeln(ans);

A. 1, 2, 3, 4
B. 2, 3, 4
C. 1, 3, 4
D. error
Answer : D
24. 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
25. Among the keywords below, which one is not a statement?
A. debugger
B. with
C. if
D. use strict
Answer : D
26. A linkage of series of prototype objects is called as ________
A. prototype stack
B. prototype chain
C. prototype class
D. prototypes
Answer : B
27. Identify the process done in the following JavaScript code snippet?
o = {x:1, y:{z:[false,null,]}};
s = JSON.stringify(o);
p = JSON.parse(s);

A. Object Encapsulation
B. Object Serialization
C. Object Abstraction
D. Object Encoding
Answer : B
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. 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
30. What will be the output of the following JavaScript code?
const obj1 =
{
property1: 21
}
const descriptor1 = Object.getOwnPropertyDescriptor(obj1, 'property1');
console.log(descriptor1.configurable);
console.log(descriptor1.enumerable);

A. true 21
B. true false
C. true true
D. false false
Answer : C
31. 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
/div>
32. 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
33. 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
34. What is the observation made in the following JavaScript code?
if (!a[i]) continue;

A. Skips the defined elements
B. Skips the existent elements
C. Skips the null elements
D. Skips the defined & existent elements
Answer : C
35. 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
36. 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
37. 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
38. The var and function are __________
A. Keywords
B. Declaration statements
C. Data types
D. Prototypes
Answer : B
39. What will be the output of the following JavaScript code?

A. 7.25
B. -7.25
C. 7
D. -7
Answer : A
40. 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
41. 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
42. The var and function are __________
A. Keywords
B. Declaration statements
C. Data types
D. Prototypes
Answer : B
43. 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
44. 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
45. 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
46. A function definition expression can be called as __________
A. Function prototype
B. Function literal
C. Function calling
D. Function declaration
Answer : B
47. 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
48. 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
49. Which is an equivalent code to invoke a function m of class o that expects two arguments x and y?
A. o(x,y);
B. o.m(x) && o.m(y);
C. m(x,y);
D. o.m(x,y); Answer : D
50. 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

Sharing is caring