Estaba leyendo y codificando junto con este tutorial de javascript.info. No puedo entender por qué en estos dos ejemplos los resultados son diferentes.
Aquí la variable de nombre de usuario cambia de "John" a "Bob":
let userName = 'John'; function showMessage() { userName = "Bob"; // (1) changed the outer variable let message = 'Hello, ' + userName; alert(message); } alert(userName); // John before the function call showMessage(); alert(userName); // Bob, the value was modified by the functionY aquí se queda "Ann":
function showMessage(from, text) { from = '*' + from + '*'; // make "from" look nicer alert(from + ': ' + text); } let from = "Ann"; showMessage(from, "Hello"); // *Ann*: Hello // the value of "from" is the same, the function modified a local copy alert(from); // Ann¿Alguien puede ayudarme a entender por qué sucede esto?