ES6 - Use Destructuring Assignment to Pass an Object as a Function's Parameters

So I’m on freeCodeCamp ES6 lesson:
Use Destructuring Assignment to Pass an Object as a Function’s Parameters.
And I put the example shown in the lesson in my browser console to practice with it, of course adding slightly to it, so as to try an pass arguments and see action with it:

const profileUpdate = ({ name, age, nationality, location }) => {
    console.log("Hello " + name + "." + "Are you " + age + "?" + "What is your nationality?" + "Answer: " + nationality );
}

// Then when I called the function with an the following argument:


profileUpdate("Chewie", 150, "Wooki");

I then get undefined for the argument output:

Hello undefined.Are you undefined?What is your nationality?Answer: undefined

Why is that?

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

Challenge: ES6 - Use Destructuring Assignment to Pass an Object as a Function’s Parameters

Link to the challenge:

Your function argument is not an object

Thank you for your quick response @JeremyLT
Please forgive me for any stupid questions, I’m just trying to understand the lesson and I always practice in VS code or my browser console by trying the examples in the lesson in different formats to try and understand the lesson.

That being said. So should I have put the arguments inside curley braces such as:

profileUpdate( { "Chewie", 150, "Wooki" } );

because I tried that and got:

Uncaught SyntaxError: missing : after property id

You’re getting closer, an object literal needs both the names of the properties and their values.

1 Like

Ok so:

profileUpdate({name:"Chewie", age: 150, nationality: "Wooki"});

// Would then give me:

Hello Chewie.Are you 150?What is your nationality?Answer: Wooki

It should, yep

1 Like

It worked!

Thanks, @JeremyLT !
Your awesome as always!
Cup of Coffee now and 2 beers this evening just for you cuz you deserve it. :grinning:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.