1

Let's say that someone asks a question, and I add this simple answer in code (context: create array of tags in document):

function countTag() {
    let tags = [];
    for (tag of document.getElementsByTagName("*")) {
        tags.push(tag.tagName);
    }
    return tags;
}
console.log("Tags: ", countTag());
<div>a</div>
<div>b</div>
<div>c</div>
<div>d</div>
<div>e</div>

But later, I do more research and find a more compact, refined way to achieve the same result, but with different compatibility:

function countTag(tag="*") {
  return [...document.getElementsByTagName(tag)].map(a => a.tagName)
}
console.log(countTag("*"))
<div>a</div>
<div>b</div>
<div>c</div>
<div>d</div>
<div>e</div>

If I want to add this new, refined code to my answer, what should I do? Should I create a new answer with the new code, add the new code as an "extra" to my original answer in an edit, or edit out the old answer entirely and replace it with the new answer?

1
  • 1
    Since this is an improvement rather than a radical rethink/alternative, I'd update the original answer. Commented Nov 29, 2020 at 20:09

1 Answer 1

5

Add the new information in your existing answer if you think like the old information still has value for some people, e.g. when it's old syntax or an old library but it's still used widely.

Rewrite your existing answer if the previous form is completely obsolete and actually causes harm, e.g. showing usage of a deprecated library while there is a new one present, or when it has security problems.

In some cases you may want to even post a new question and answer it yourself if editting an answer would leave the overall post (question + answer) in a somewhat inconsistent state.

This should be decided on a case-to-case basis.

I don't think there's any case where you want to post two answers.

3
  • What if you have two different answers to the same question? Then two answers would be reasonable.
    – cigien
    Commented Nov 29, 2020 at 20:17
  • @cigien I think if a question has seemingly two valid answers (that cannot be merged to a single answer for any reason), it should most likely be closed for lacking focus. ¯\_(ツ)_/¯ But yeah, there are probably some cases, but I think posting two answers should definitely be the "last choice".
    – akuzminykh
    Commented Nov 29, 2020 at 20:19
  • 2
    I have come across some cases where two different answers are valid, but I agree they are not very common. And it should certainly be the last choice.
    – cigien
    Commented Nov 29, 2020 at 20:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .