JavaScript Questions & Answers – Array and Related Methods | JavaScript MCQs

Sports GK Questions and Answers 2024 (Latest Updated)

Awards & Honours GK Questions 2024 (Latest Updated)

Questions
1 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: The omitted value takes “undefined”
2 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: true false
Advertisement
Article and Schedule Quiz Start Test!
DOWNLOAD CURRENT AFFAIRS PDF FROM APP
3 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
B updates the element

Answer: decrements the total length by 1
4 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: Skips the null elements
5 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
B Floating point

Answer: Reverses and stores in the same array
6 What will be the possible output of the following JavaScript code?

var a = [1,2,3,4,5];

a.slice(0,3);

A Returns [1,2,3]
B Returns [4,5]
C Returns [1,2,3,4]
D Returns [1,2,3,4,5]

Answer: Returns [1,2,3]
7 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: 1
8 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: 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
9 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: inject and fold
10 The method or operator used to identify the array is __________
A isarrayType()
B ==
C ===
D typeof

Answer: typeof
11 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: 1, 2, 3, 6, 7, 8
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: error
13 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: 75
14 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: one
15 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: 3, 2, 1

Random GK Questions

Assam Direct Recruitment Test Series

Teacher Eligibility Test

Assam Direct Recruitment Test Series