Multiple choice technology programming languages

What is the output of the below JavaScript?


var one = ["a", "b", "c", "d"];         
alert(one.slice(-2));       

  1. error

  2. a,b

  3. a,b,c,d

  4. c,d

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The slice(-2) method extracts the last two elements of the array, returning ["c", "d"]. When passed to alert(), the array is implicitly converted to a string, resulting in the comma-separated output "c,d".