source-academy / cs1101s

1 stars 0 forks source link

What is the difference between const and let? #17

Open mrqorib opened 3 years ago

mrqorib commented 3 years ago

Question: is there a difference between const a = []; and let a = [];? Piazza: https://piazza.com/class/kas136yscf8605?cid=632#

mrqorib commented 3 years ago

Answer: let allows you to reassign the name to some other value -- like another array, or a number, or a string, etc. const means that name cannot be reassigned, so const a will mean that a will always refer to that array (unless overridden by another name binding elsewhere)