Home

SSC JHT - JavaScript 1000+ MCQ [Solved] PDF Download

Thursday 9th of March 2023

Sharing is caring

1. 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
2. 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
3. A hexadecimal literal begins with __________
A. 00
B. 0x
C. 0X
D. Both 0x and 0X
Answer : D
4. 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
5. 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
6. What will be the output of the following JavaScript code?

A. 125
B. 25
C. 5
D. Error
Answer : C
7. 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
8. 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
9. 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
10. 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
11. 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
12. 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
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?
var txt1 = good;
var txt2 = day;
document.getElementById(demo).innerHTML = txt1 + txt2;

 


A. good day
B. goodday
C. error
D. undefined
Answer : B
15. 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
16. 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
17. 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
18. What will be the output of the following JavaScript code?

A. 7.25
B. -7.25
C. 7
D. -7
Answer : A
19. 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
20. 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
21. 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
22. 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
23. 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
24. What will be the output of the following JavaScript code?
var pow=new Function(num1,num2,return Math.pow(num1,num2));
document.writeln(pow(2,3));

A. 2
B. 3
C. 8
D. error
Answer : C
25. 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
26. 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
27. 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
28. Among the following, which one is a ternary operator?
A. +
B. :
C. ^
D. ?:
Answer : D
29. A JavaScript program developed on a Unix Machine ________
A. will throw errors and exceptions
B. must be restricted to a Unix Machine only
C. will work perfectly well on a Windows Machine
D. will be displayed as a JavaScript text on the browser
Answer : C
30. 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
31. 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
32. 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
33. The var and function are __________
A. Keywords
B. Declaration statements
C. Data types
D. Prototypes
Answer : B
34. 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
35. 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
36. 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
37. 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
38. 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
39. What happens in the following javaScript code snippet?
var count = 0;
while (count < 10)
{
console.log(count);
count++;
}

A. The values of count are logged or stored in a particular location or storage
B. The value of count from 0 to 9 is displayed in the console
C. An error is displayed
D. An exception is thrown
Answer : B
40. 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
41. 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
42. 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
43. What happens in the following javaScript code snippet?
var count = 0;
while (count < 10)
{
console.log(count);
count++;
}

A. The values of count are logged or stored in a particular location or storage
B. The value of count from 0 to 9 is displayed in the console
C. An error is displayed
D. An exception is thrown
Answer : B
44. 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
45. 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
46. 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
47. 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
48. What will be the output of the following JavaScript code?
var grade='B';
var result;
switch(grade)
{
cae '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
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. A function with no return value is called ___________
A. Procedures
B. Method
C. Static function
D. Dynamic function
Answer : A

Sharing is caring