...

/

Assignment Operator

Assignment Operator

This lesson explains the use of the assignment operator with object variables.

We'll cover the following...

What is an assignment operator?

Assingment is giving a new value to an existing object:

returnTripDuration = tripDuration; // assignment

The assignment is more complicated than the other special operations because it is actually a combination of two operations:

  • Destroying the left-hand side object

  • Copying the right-hand side object to the left-hand side object

svg viewer

However, applying those two steps in that order is risky because the original object would be destroyed before knowing that copying will ...