Referenced Variables As Parameters

This lesson explains how referenced variables are not copied when used with functions.

Referenced variables are not copied #

Even parameters of reference types like slices, associative arrays and class variables are copied to functions. However, the original variables that are referenced (i.e. elements of slices and associative arrays and class objects) are not copied. Effectively, such variables are passed to functions as references; the parameter becomes another reference to the original object. It means that a modification made through the reference modifies the original object as well.
Since strings are slices made up of characters, this concept applies to strings as well:

Get hands-on with 1200+ tech skills courses.