Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let condiments = ['Ketchup', 'Mustard', 'Soy Sauce', 'Sriracha'];
- const utensils = ['Fork', 'Knife', 'Chopsticks', 'Spork'];
- //Re-assign the first element to value 'Mayo' and array now becomes [ 'Mayo', 'Mustard', 'Soy Sauce', 'Sriracha']
- condiments[0] = 'Mayo';
- console.log(condiments);
- //Now re-assign condiments as a new array that contains a single string ['Mayo']
- //this can be done because array was created with the let keyword
- condiments = ['Mayo'];
- console.log(condiments);
- //Re-assign the last element to value 'Spoon' and array now becomes [ 'Fork', 'Knife', 'Chopsticks', 'Spoon']
- //this can be done because we can change the contents of const array as it remains mutable
- utensils[3] ='Spoon';
- console.log(utensils);
- //however we cannot reassign a new array or a different value.
- utensils = ['Spoon'];
- console.log(utensils); //will result in TypeError
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement