I see a lot of questions where the poster has assumed that a function works in place (for example, the way JavaScript Array.sort
works) and consequently failed to assign the result of the function call to the variable they wish to change. For example with JavaScript Array.concat
users will write:
let arr = [ /* some array data */ ];
arr.concat(arr2);
where they should have written:
arr = arr.concat(arr2);
I also (to a lesser extent) see questions where people expect the return value from a function which modifies the input in place to be the modified input (e.g. JavaScript Array.splice
).
Is it appropriate to close these questions as typos/non-reproducible? Should they even be closed at all? If they should be closed, but not as typos, what is the appropriate close reason? Because of the sheer number of such functions it doesn't seem practical to set up a canonical that would allow these questions to be closed as duplicates.
.replace
too: stackoverflow.com/q/1433212 Nothing wrong with setting up canonicals, or figuring out an existing one to link to for each type of problem. Don't have just one, of course, have one for each sort of situation/language.someArray = someArray.push(xyz)
in its code. I voted to close it as a duplicate of Why do I get “.push not a function”?. Some of these “canonicals” do exist.