0 votes
in JavaScript by
Which one of the following options is the correct output for the given code of javascript?

var values=[4,5,6,7]  

varans=values.slice(1);  

document.writeln(ans);  

a) Error

b) 5, 6, 7

c) 4, 5, 6,

d) 4, 5, 6, 7

1 Answer

0 votes
by

Answer: A

Explanation: The "slice()" method used in the above program a built-in function of the JavaScript and it is used to delete/remove the data items from the array. In general, it requires two arguments,in which first one for starting point and another one for the ending point. For example, consider the following given code:

<script>
function myFunction() {
  var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
  var myBest = fruits.slice(-3, -1);
document.getElementById("demo").innerHTML = myBest;
}
</script>

Output

Lemon,Apple

However, we can see that in given question only one argument is passed, so it will definitely result in an error.

Related questions

+1 vote
asked Mar 22, 2021 in JavaScript by Robindeniel
0 votes
asked Mar 22, 2021 in JavaScript by Robindeniel
...