I’m working on a JavaScript project, and I’ve encountered an issue with an “undefined variable” error. Here is the relevant part of my code:
function calculateSum(a, b) {
return a + b + c;
}
let result = calculateSum(5, 10);
console.log(result);
When I run this code, I get the following error in the console:
Uncaught ReferenceError: c is not defined
at calculateSum (script.js:2)
at script.js:5
I understand that the error is because c is not defined, but I’m not sure how to fix it. Could someone explain what I need to do to resolve this error?
I’ve checked the variable names to make sure there are no typos.
I’ve tried declaring c inside the function, but I need it to be dynamic based on some conditions.
Any help or suggestions would be appreciated. Thanks!