0

came across following code, just don't understand how it works even without an explicit destructuring assignment?

const createUser = ({ userName, avatar }) => ({
  userName,
  avatar
})

console.log(createUser({ userName : 'user1', avatar : 'avatar'}))
1

1 Answer 1

3

You have indeed a destructuring here:

const createUser = ({ userName, avatar }) => ...

Because that is a shorthand for:

const createUser = (params) => {
    let { userName, avatar } = params;

Notice your function is not receiving two parameters, just one, and is destructuring it right away.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.