Learn
Arrays
Arrays with let and const
Using let
with Arrays:
The let
keyword allows us to declare variables that can be reassigned. When using let
with arrays, we can update the array elements and even reassign the array entirely. Here's an example:
By using let
, we have the flexibility to modify and reassign the array as needed.
Using const
with Arrays:
The const
keyword, on the other hand, creates variables that cannot be reassigned. When using const
with arrays, we can still modify individual elements, but we cannot assign a new array to the variable. Let's see an example:
With const
, we can be certain that the array itself cannot be overwritten, providing a level of immutability and stability to our code.
code.
Instructions
Declare a constant variable named fruits
and assign it an array of strings containing the names of some fruits, at least 4 elements.
Access and print the third element of the fruits
array using index notation.
Update the fourth element of the fruits
array to be "banana"
using index notation.
Print the updated fruits
array.
Sign up to start coding
Already have an account?
Sign In