Skip to content

Instantly share code, notes, and snippets.

@nodox
Last active August 29, 2018 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nodox/182b1f394543a13ed37bc5299500e587 to your computer and use it in GitHub Desktop.
Save nodox/182b1f394543a13ed37bc5299500e587 to your computer and use it in GitHub Desktop.

Michael

if I wanted to make something lowercase I would do this

const x = (name) => 
  name = name.toLowerCase()

But since its one parameter is there a way i could make it lowercase without specifying the parameter? Since arrow functions dont require it for one parameter.

const x = () => // can i put anything here? Or do i have to define a parameter.

Steven

const x = (name) => name = name.toLowerCase()

This means that your function returns a variable that is assigned the arugment in lowercase form. I guess that could work--let me know the output--however when you read the function as I did it doesn't make much sense. Another problem here is that the new name variable actually references the argument, so oyu are overriding the argument and then returning it which is not a good practice. Because if you ever want the original value you will have lost it.

So let's actually write out what we want to do verbally.

I want a constant variable to be assigned a function. The function takes a parameter called name and returns the lowercase version of the string.

const myFunction = name => name.toLowercase()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment