Declaring arrays knowing their maximum size
Interesting question,

first off, you are worrying about the wrong things. Even if the first approach provides some better performance, (which I think unlikely), it would be premature optimization.

The right way would be simply:

var marks = [40, 100, 1, 5, 25, 10];
document.getElementById("demo").innerHTML = marks[3];


Now, from a memory perspective, I am pretty sure that the only thing happening with new Array(6); is the setting of length to 6. It does not mean that memory is allocated. If you think about that, assigning memory would be silly because JS does not know what you will put in that array, it could be an integer or it could be a really long string, or a function or an object, you get the point..

My advise is to code in an idiomatic way, simply expressing what needs to be done.