How To "Put" An Array Into An Argument (SOLVED)

Hello, I want to “put” an object (var person) into the function through the argument (thus giving me “John Smith”), but it says there’s a syntax error. What could it be?

function addFullNameProperty(obj) {
    var fullName = obj.firstName + '  ' + obj.lastName
    return fullName
}

addFullNameProperty(var person = {firstName: "John", lastName: 'Smith';})

you can’t declare a variable and also at the same time pass it into the function

or you simply pass the object literal in the function

addFullNameProperty({firstName: "John", lastName: 'Smith';})

or you first declare the variable and then pass it into the function

var person = {firstName: "John", lastName: 'Smith'};
addFullNameProperty(person);
2 Likes

Then you would need to move the declaration outside (before) you call the addFullNameProperty function and pass the declared object as the argument to the function.

2 Likes