
assign4 java script caveats ...
- Strings are objects, not primitives. Assigning string2=string1 makes string1 AND string2 references equal and pointing to the same object. This did not bode well when attempting to only reset string2. String1 was reset also because they referred to the same object.
- The String class constructor needed to be invoked: string2 = new String(string1);
string1 and string2 now their own separate copies, so wiping one out has no effect on the other.
No comments:
Post a Comment