Changing you local variable does not change the stored data. If you want to change the stored data, call .data() with two parameters.
While you didn't ask... nor does changing the stored data (using .data() with two parameters) change the attribute in the DOM.
The DOM attribute INITIALIZES the internal data store for .data() on first reference.
I do agree perhaps it could use more clear documentation. Maybe it should be made clear that .data() doesn't pass back a reference to it's internal data store, but (apparently) a reference to a new object with a copy of the internal data.
The documentation is ambiguous, as it refers to returning a "value". But Javascript returns by reference, other than simple variables.