Basic JavaScript - Use Recursion to Create a Countdown

1.In javascript can we declare an array with val and let keywords and if not then why?
2.When we declare an array with const keyword we can access, change array elements, push, pop, shift, unshift array elements although we have studied that const keyword doesnot allow redeclaring and reassigning of a variable?

You can declare an array with let or const. I wouldn’t use var as it’s basically obsolete now, having been superseded by the other two.

Using const means that you cannot reassign the variable, but you can still modify the array.

The const declaration creates a read-only reference to a value. It does not mean the value it holds is immutable—just that the variable identifier cannot be reassigned. For instance, in the case where the content is an object, this means the object’s contents (e.g., its properties) can be altered.


it means if i have an array
const countArray=[1,2,3,4];
i can do something like:
but cannot do:
const countArray=[6,7,8]

Yes, that is correct.


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.