Calling Object into Functions?

https://www.codecademy.com/courses/introduction-to-javascript/lessons/objects/exercises/pass-by-reference

let spaceship = {
  homePlanet : 'Earth',
  color : 'red'
};
let tryReassignment = obj => {
  obj = {
    identified : false, 
    'transport type' : 'flying'
  }
  console.log(obj) // Prints {'identified': false, 'transport type': 'flying'}
 
};
tryReassignment(spaceship) // The attempt at reassignment does not work.
spaceship // Still returns {homePlanet : 'Earth', color : 'red'};
 
spaceship = {
  identified : false, 
  'transport type': 'flying'
}; // Regular reassignment still works.
  • 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!

The above explanation about calling an Object straight into
a Function that will not work is not clear . can someone
interpret it in a very simple form / a layman’s term please.

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