let with Arrays:
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:
let, we have the flexibility to modify and reassign the array as needed.
const with Arrays:
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:
const, we can be certain that the array itself cannot be overwritten, providing a level of immutability and stability to our code.
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
Sign up to start coding
Already have an account?