I made this edit to correct a syntax error in some JavaScript code in an answer.
I added the var
keyword to the code. Before my edit, values were being assigned to undefined variables.
This accepted answer suggests that correcting a syntax error in code in an answer is a good enough reason to make an edit.
My edit was rejected by three different users, twice because the "changes are either completely superfluous or actively harm readability" - and once because it "was intended to address the author of the post and makes no sense as an edit."
I believe that the correction of a syntax error improves the quality of the answer, so why was my edit rejected?
Before my edit, values were being assigned to undefined variables.
Yes, they were, and the code will function just fine when doing that, so you're not actually fixing a problem. It would probably be better practice to scope the variable locally, but that's a matter of preference, and not something that you should be changing in another's post in an edit.var
keyword. On that basis I would argue that thevar
is necessary to ensure that the answer works as intended by the answerer'use strict';
and any global declarations like this would throw an error. Using var will always work, and going without the var causes a reference error in strict mode. Shame to see good practices are being rejected because sloppy JS can work sometimes, even if they fail in strict mode.