Why reassigning object using function fails

let human = {
    name: "Hazem",
    age: 23,

function change(obj) {
    new_obj = {
        second_name: "Mohamed",
        job : "teacher"


in the above code reassigning object using function fails despite of I’m using let when i create human object when i read the following description

We declared this spaceship object with let. This allowed us to reassign it to a new object with identified and ‘transport type’ properties with no problems. When we tried the same thing using a function designed to reassign the object passed into it, the reassignment didn’t stick (even though calling console.log() on the object produced the expected result).When we passed spaceship into that function, obj became a reference to the memory location of the spaceship object, but not to the spaceship variable. This is because the obj parameter of the tryReassignment() function is a variable in its own right. The body of tryReassignment() has no knowledge of the spaceship variable at all! When we did the reassignment in the body of tryReassignment(), the obj variable came to refer to the memory location of the object {‘identified’ : false, ‘transport type’ : ‘flying’}, while the spaceship variable was completely unchanged from its earlier value…

on this point in the lesson i didn’t understand it can anyone help me to understand why this fails


It’s not quite so much that this fails, it just doesn’t do what you expect.
When you pass an argument into a function, you usually either affect that or take something from it.

So for example, in your function change you take an obj, but you never order any type of changes to that obj specifically.

Other things to consider are scope, and return values in functions. Review these and let us know if you have any further questions :slight_smile: