Predict Default Parameters
Predict Output Easy
Question
What does this code print?
Code
function greet(name = "Guest") {
return "Hello, " + name;
}
console.log(greet());
console.log(greet("Ada"));
Hint
Default parameters are used when the argument is not provided.
Explanation
When greet() is called with no argument, name defaults to "Guest", so it returns "Hello, Guest". When greet("Ada") is called, name is "Ada", so it returns "Hello, Ada". Each result is printed on its own line.
Related Resources
Related Lessons
- JavaScript Functions
Learn about default parameters.
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.