Spot the Function Syntax Error
Question
This JavaScript function has a syntax error. Identify what is wrong.
Code
function greet(name)
return "Hello, " + name;
}
console.log(greet("Ada"));
Hint
A function body needs to be wrapped in curly braces.
Explanation
A function body must be enclosed in curly braces { }. The opening { is missing after the parameter list (name). The corrected code is: function greet(name) { return "Hello, " + name; }. Without the braces, JavaScript cannot parse where the function body begins.
Related Resources
Related Lessons
- Functions
Learn how functions work in programming.
Related Cheatsheets
- JavaScript Cheatsheet
Quick reference for JavaScript function syntax.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.