Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for LeetCode 2667. Create Hello World Function (Easy)
Julia 👩🏻‍💻 GDE
Julia 👩🏻‍💻 GDE

Posted on

     

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 functioncreateHelloWorld. 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.

varcreateHelloWorld=function(){returnfunction(){return"Hello World"}}
Enter fullscreen modeExit fullscreen mode

What happens here?

varcreateHelloWorld=function(){}
Enter fullscreen modeExit fullscreen mode

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

👻Note: I personally never usevar when declaring a variable, I always opt forlet orconst, but since this was the default, I'll keep it that way (there's nothing really wrong with usingvar).

Return a function

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

returnfunction(){}
Enter fullscreen modeExit fullscreen mode

Always return "Hello World"

By adding

return"Hello World"
Enter fullscreen modeExit 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)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

👋 Selftaught Accessibility & Frontend Developer💻 Dev & UX Accessibility Specialist @Atos | CPACC🙆 Improving the world with accessible web content✍️ Content creator, Tips on How To Get Into Tech
  • Location
    Vienna, Austria
  • Education
    selftaught
  • Work
    Frontend & Accessibility Developer
  • Joined

More fromJulia 👩🏻‍💻 GDE

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp