0 votes
in JavaScript by

What will happen if we execute the following piece of code?

<script>  

  

var arr=[4,3,,1];    

  for(i=0;i<4;i++){  

document.writeln(arr[i]);  

}  

</script>  
 

a) The output will be 4 3 1

b) The output will be 4 3 undefined 1

c) It will result in an error

d) It does not run at all

1 Answer

0 votes
by

Answer: B

Reason: In JavaScript, if user defines an array and does not define value of any element, there will be no error. But if user tries to print the element of the array whose value is not defined, it will print the "undefined" as the value of that element.

Related questions

0 votes
asked Mar 23, 2021 in JavaScript by sharadyadav1986
0 votes
asked Mar 22, 2021 in JavaScript by Robindeniel
...