What will be the output of the following JavaScript code? [code] var values=[1,2,3,4] var ans=values.slice(1); document.writeln(ans);

Ánh Dương

New member
What will be the output of the following JavaScript code?
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
Explanation: slice function is used to remove values from the array. The slice function accepts two arguments as the starting and ending values for slicing elements. As in the above function, only one argument is passed therefore it will result in an error.
 

Tìm kiếm

Back
Top