What will be the possible output of the following JavaScript code? [code] var a = [1,2,3,4,5]; a.slice(0,3); [/code]

Việt Quân

New member
What will be the possible output of the following JavaScript code?
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: a
Explanation: .slice() function is a predefined function in JavaScript used to keep the elements from starting point and ending point mentioned in the function argument. The elements after the ending point and before the starting point are not shown.
 

Tìm kiếm

Back
Top