Welcome to the Treehouse Community
Looking to learn something new?
Blake Powell4,175 Points
What happens to joel kraft
so i get why it keeps the name andrew, but not quite clear on whats happening within the function. because you change it from a variable to a constant, the scope is limited to within the function correct? but what can happen with that new constant now, wouldn't it have to find its way into another variable/constant to be of any use?
a separate question, we may be getting to this later, but with the first variable being changed to a constant i see that it can't be replaced, but can we add to the string with a +=to create a simple list?
Steven Parker216,057 Points
After the change, there are two constants.
Originally, the function uses the global name, that's why there is an error when the global name is changed to a constant. But when "const" is put in front of name inside the function, a new constant is created which has the scope limited to within the function. It lasts long enough to use it in the call to console.log.
A constant cannot be changed., that means neither a normal assignment ("
=") nor an addition assignment ("
+=") can be used on it.
Ana Luiza Barreto Marinho2,210 Points
Not really, no... That new constant is locked to that function's scope, that means for all the rest of the program cares, the only variable available is the first
const name = Andrew, the other one doesn't exist. That implies that you can still use it inside that function and use the function in the code with no problem what so ever :).
Now that second question: no, it can't be modified in any way... not modifying the whole value or parts of it :).