Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Default Parameter Greeting

A Closer Look at Functionseasy

Course · Section 10: A Closer Look at Functions · Lecture 135: Default Parameters

Implement `greet(name, greeting)` that returns `"<greeting>, <name>!"`. If `greeting` is not provided, default to `"Hello"`.

Sample tests

Input: greet("Alice")
Output: "Hello, Alice!"
Input: greet("Bob", "Hi")
Output: "Hi, Bob!"

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Defaults apply only to undefined, not to empty string or null.

Learning resources

  • MDN: Default parameters
Approach & explanation (try first)

The default value supplies a fallback name only when the argument is undefined.

Loading...
⌘/Ctrl + Enter

Run your code to see results.