DEV Community

Cover image for LeetCode 2667. Create Hello World Function (Easy)
49

LeetCode 2667. Create Hello World Function (Easy)

Could you solve the last LeetCode problem? ๐Ÿค“ Here's another one, the simplest of the simplest. But hey, we all have to start somewhere.

Starting point

Write a function createHelloWorld. It should return a new function that always returns "Hello World".

My Submission

Let's take a look at my code. Yours maybe looks different, and that's okay. Everyone has their own approach.

var createHelloWorld = function() {
     return function() {
        return "Hello World"
     }
 }
Enter fullscreen mode Exit fullscreen mode

What happens here?

var createHelloWorld = function() {

 }
Enter fullscreen mode Exit fullscreen mode

What was given by LeetCode was the outer declaration, the initialization of var createHelloWorld, which was assigned a function.

๐Ÿ‘ป Note: I personally never use var when declaring a variable, I always opt for let or const, but since this was the default, I'll keep it that way (there's nothing really wrong with using var).

Return a function

In the description it is said that we should return a function, which I did by writing

return function() {

}
Enter fullscreen mode Exit fullscreen mode

Always return "Hello World"

By adding

return "Hello World"
Enter fullscreen mode Exit fullscreen mode

inside the function, the string "Hello World" will be returned, no matter which argument the function may get.


In general, I am bad at explaining technical stuff. So any advice is welcome to improve my explanation skills ๐Ÿ™๐Ÿฝ.

Top comments (0)

For IaC Practitioners, By IaC Practitioners

For IaC Practitioners, By IaC Practitioners

Learn how to embed security from day one using policy-as-code, AI-driven scanning, and strong collaboration between engineering and cybersecurity teams at IaCConf on Wednesday August 27, 2025.

Join us on August 27

๐Ÿ‘‹ Kindness is contagious

Sign in to DEV to enjoy its full potential.

Unlock a customized interface with dark mode, personal reading preferences, and more.

Okay