What will this code log? function greeting(name = 'Guest') { let name = 'User'; return `Hello, ${name}`; } console.log(greeting());
This code will throw a `SyntaxError: Identifier 'name' has already been declared`. In JavaScript, function parameters create variables in the function scope. Attempting to declare a variable with the same name using `let`, `const`, or `var` within the same scope will cause a SyntaxError. The parameter `name` (with its default value 'Guest') is already a variable in the function scope, so declaring another variable with `let name = 'User'` in the same scope is not allowed. This error occurs at parse time, before the function is ever executed. To fix this issue, you would need to use a different variable name inside the function, or simply reassign the parameter value without redeclaring it (e.g., `name = 'User'` without the `let` keyword). This behavior is consistent with how variables work in JavaScript—identifiers must be unique within a given scope, whether they're introduced as parameters, `let`/`const`/`var` declarations, function declarations, or other binding forms.