Create Hello World Function - Problem
Write a function createHelloWorld that returns a new function that always returns "Hello World".
The returned function should ignore any arguments passed to it and consistently return the string "Hello World".
This problem demonstrates JavaScript concepts like closures and function factories.
Input & Output
Example 1 — Basic Function Creation
$
Input:
f = createHelloWorld()
›
Output:
"Hello World"
💡 Note:
createHelloWorld() returns a function that always returns "Hello World" when called, regardless of arguments
Example 2 — Function with Arguments
$
Input:
f = createHelloWorld(); f({}, null, 42)
›
Output:
"Hello World"
💡 Note:
Even when called with arguments, the returned function ignores them and returns "Hello World"
Example 3 — Multiple Calls
$
Input:
f = createHelloWorld(); [f(), f(), f()]
›
Output:
["Hello World", "Hello World", "Hello World"]
💡 Note:
The function consistently returns the same string on every call
Constraints
- The function must return exactly "Hello World"
- Arguments passed to returned function should be ignored
- Function should work consistently across multiple calls
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code