22

What characters are valid for JavaScript variable names?

I'm perplexed; to my understanding such questions should be perfectly valid for Stack Overflow; yet it is historically locked?

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here.

Can someone enlighten me, what is so off-topic with this question?

From Help center it is on-topic to ask about:

a practical, answerable problem that is unique to software development

How does this question not fulfill this?

19
  • 8
    It starts with "Can anyone point me to a Web page..." -- off-site resource requests are off-topic. Commented Jun 5, 2018 at 13:33
  • 6
    @MikeMcCaughan In this case this Web page answers should point to is probably EcmaScript specification; and even if the OP wasn't asking for that, the answers should likely still provide such a link as a reference; and if for some reason this particular sentence is still problematic in the question (though I fail to see how), why can't it be simply edited out?
    – user4385532
    Commented Jun 5, 2018 at 13:37
  • 3
    It is not closed as off-topic, a historical lock prevents the Q+A from being deleted. Clearly Mathias' post deserves to be protected and no new answers are necessary. Commented Jun 5, 2018 at 13:37
  • 3
    @HansPassant Umm nope, at least according to meta.stackexchange.com/questions/126587/…
    – user4385532
    Commented Jun 5, 2018 at 13:39
  • It confirms it, "preserves content that was very popular". It is still pretty popular btw, no doubt thanks to high Google ranking. Basic way Q+A like this gets a quarter of a million views. Commented Jun 5, 2018 at 13:41
  • 6
    @HansPassant my link explicitly states that historical lock is only appropriate when "the post does not meet the current guidelines for a good, on-topic question". If what you say was true, then a regular lock would be used rather than a historical one
    – user4385532
    Commented Jun 5, 2018 at 13:43
  • A regular lock does not stop users from flagging the question. Moderators do get fed up with constantly having to reject flags, the lock stops that. Commented Jun 5, 2018 at 13:44
  • 2
    @HansPassant "a historical lock prevents the Q+A from being deleted" -- While this would be a fair reason for locking, wouldn't it be atypical to take it as a preemptive measure? According to the timeline, the question was never closed or deleted, and its only (invalidated) close review happened seven months before the lock. (That said, your rationale about undue flagging would make for a better justification, though I still wonder if, in this case, an edit wouldn't have been enough to stem that.)
    – duplode
    Commented Jun 5, 2018 at 13:50
  • 9
    I think the appropriate action for this question is to remove the request for an off-site resource, and unlock it. That way it's on topic, and I don't see further problems with it. You can protect it, to prevent some of the bad answers rolling in
    – Erik A
    Commented Jun 5, 2018 at 15:55
  • 1
    The last paragraph seems to be asking for an opinion-based answer as well. Commented Jun 5, 2018 at 22:26
  • 1
    @JohnMontgomery Not really. That paragraph just states the motivation of the OP for asking the question; it isn't an essential part of it.
    – duplode
    Commented Jun 6, 2018 at 1:38
  • 1
    @duplode "I'm posing this question to the many JavaScript sensei of the world for advice about what characters (even if valid) would be a bad idea to use" seems to be asking for an opinion to me. It's a different question from the one in the title too. Commented Jun 6, 2018 at 2:45
  • 3
    @JohnMontgomery That still seems sufficiently objective to me to be. Sure, "bad idea" isn't a very formal definition, but some (made-up) things that I can imagine that would make a character a "bad idea" to use - like, it's an error in IE7, was illegal in an old spec version, or shows up HTML-entity-encoded in the Chrome console - would all involve the answerer drawing upon concrete technical knowledge. Unless the asker already knows what these hypothetical pitfalls are in advance - in which case they wouldn't need to ask the question - there's no way they can reasonably be more specific.
    – Mark Amery
    Commented Jun 6, 2018 at 11:19
  • 4
    It's off-topic because it is answerable by reading the language specification, and SO should not become a repository of copies of the specification, let alone possible misinterpretations or mis-statements of it.
    – user207421
    Commented Jun 7, 2018 at 0:15
  • 2
    @EJP That doesn't make the question off-topic. If questions were off-topic if their answer could in principle be obtained from reading another source, then we'd have to close over 99% of the site's questions. Only a couple of questions I've ever answered meet the standard (ones involving bugs in frameworks that nobody else had ever noticed or written about), and I imagine the same is true for you.
    – Mark Amery
    Commented Jun 7, 2018 at 13:58

2 Answers 2

19

As far as the on-topicness of the question goes, the one objectionable thing I see is the beginning of the first sentence:

Can anyone point me to a Web page detailing the characters [...]

"Point[ing the OP] to a Web page" amounts to an off-site resource recommendation, which is off-topic and a close reason. In this specific case, though, the resource request is completely superfluous, and could be edited away without significantly affecting the goal of the question or the range of acceptable answers. Instead of closing or locking it, I would say a more natural course of action would be simply editing it to:

What are the characters [...]

10
  • 6
    Shouldn't an answer link to off-site resources anyway, for a reference? For the same exact reason why Wikipedia requires all statements to be backed up by citations?
    – user4385532
    Commented Jun 5, 2018 at 13:43
  • 13
    @gaazkam Linking to other sites to support an answer and provide references is useful and recommended, indeed. The problem with "Can anyone point me to [...]" is that it invites answers that consist only of a link, which are not acceptable. Asking the actual question directly instead makes it clear that answers should include a substantial answer of some sort, and not merely a pointer to something else.
    – duplode
    Commented Jun 5, 2018 at 13:54
  • 7
    @pnuts Removing the spurious note that warns that this question is off-topic and subsequent questions like this are not welcome here.
    – user4385532
    Commented Jun 5, 2018 at 18:00
  • 13
    @pnuts Then, is it wrong to ask what characters can be used in Javascript variable names? This is the impression a random visitor is likely to have.
    – user4385532
    Commented Jun 5, 2018 at 18:04
  • 5
    @pnuts The fact that Matthias Bynens' answer is based upon an old spec and he cannot update it due to the lock seems like a solid justification for unlocking - although I reject the idea that we should have to point to some specific useful action that could be taken just to justify an unlocking. Even on a question where we can't see any further useful contribution, somebody else might.
    – Mark Amery
    Commented Jun 5, 2018 at 22:49
  • 7
    @pnuts Because this question already is on-topic, a new one would likely be closed as a duplicate of it, and this one already has Google-juice and a useful answer.
    – Mark Amery
    Commented Jun 5, 2018 at 22:57
  • 11
    @pnuts And I (and, clearly, others here) think that that locking is patently incorrect. As duplode points out in this answer, the only possible rationale for considering the question off-topic can be fixed with a 9-word edit that has no practical impact on the meaning of the question at all. Such a question is not off-topic, and treating it as being so is an pointlessly literalistic reading of the rules.
    – Mark Amery
    Commented Jun 5, 2018 at 23:00
  • 11
    @pnuts But to argue that it's a substantial difference is absurd. Can I just check here that literally the only problem you have with this question is the words "Can anyone point me to a Web page", and that there's not some other issue I'm missing? And you understand that the (non-deleted) answers it's received do not in fact merely point to a web page, but are valid answers to an equivalent question with those words removed? How can there be a "substantial difference" if this question has in fact been interpreted and answered as if it the words you object to were not present?
    – Mark Amery
    Commented Jun 5, 2018 at 23:08
  • 11
    @pnuts And? I'm not sure how that's relevant to the on-topicness of the question.
    – Mark Amery
    Commented Jun 5, 2018 at 23:11
  • 4
    The consensus seems to be that this is safe to unlock, so I've done so.
    – Brad Larson Mod
    Commented Jun 7, 2018 at 15:28
4

While I think duplode has a point, a better one is that the question is not really objectively answerable as asked (emphasis mine, parentheticals removed for clarity)

I realize that I could just test out a number of characters, but I'm posing this question to the many JavaScript sensei of the world for advice about what characters would be a bad idea to use (in consideration of future integration with another popular library, perhaps).

If you read the entire question, it could be summed up as

jQuery uses $. What special character do you think I should use in my JavaScript library?

The answers (which are great) really answer only the title

What characters are valid for JavaScript variable names?

This leaves us with a conundrum. The title is incorrect for the question, but the question itself is asking for opinions, which is off-topic. We could edit the question to match the title, but that radically changes the meaning. So a historical lock was applied to prevent a flood of additional opinions (all of which were deleted). Even if we did fix the question to be on-topic, it's an old canonical and might need to be locked anyways, just like this question, lest we get a lot of people only providing their own spin on the answer

8
  • 1
    I'd still rather see the entire question nuked from orbit, since anyone who really wants to know what legal characters there are in JavaScript could consult the spec, but this is probably the strongest point on the matter about it.
    – Makoto
    Commented Jun 7, 2018 at 15:04
  • @Machavity Is a question that asks: "Are there any compatibility issues that may arise with certain libraries / browsers if I use certain characters in variable names" off-topic? meta.stackoverflow.com/questions/369041/…
    – user4385532
    Commented Jun 7, 2018 at 15:16
  • 1
    @gaazkam: Funny, I recall downvoting at least one of those questions. The other one only describes what should happen when presented with the question. My comment is clear: it's better in my mind not to answer at all.
    – Makoto
    Commented Jun 7, 2018 at 15:20
  • @gaazkam: That wasn't the question being posed. But again, I'd argue that it's still off-topic since experimentation and exploration is still a natural part of software development, and they'd get their answer an order of magnitude faster if they didn't ask us if trying this would break things.
    – Makoto
    Commented Jun 7, 2018 at 15:21
  • @gaazkam Sounds somewhat broad (there's a ton of JS libraries), but it's probably got some sort of objective answer. With a small enough scope, probably on-topic. But that's not what the OP was asking here
    – Machavity Mod
    Commented Jun 7, 2018 at 15:22
  • @Machavity If the superfluous resource request is edited away (cf. my answer), the question in the title will also show up in the question body. As for the final paragraph, I see it primarily as a statement of the OP's motivation for asking the question -- it is somewhat superfluous too, and I'd say it would be fine to remove it too if we really thought it was problematic (though personally I don't find that necessary).
    – duplode
    Commented Jun 7, 2018 at 15:38
  • 1
    @duplode Fair enough. Made an edit to that effect so it cannot be construed that way any more.
    – Machavity Mod
    Commented Jun 7, 2018 at 15:43

You must log in to answer this question.