Declarations (esp. of Globals)

Discussion in 'Javascript' started by Gene Wirchenko, Nov 29, 2011.

  1. Dear JavaScripters:

    There is nothing quite like checking out someone else's code. "He
    is doing it all wrong!" is a thought that can all-too-easily come to
    mind or mouth.

    It is a bit awkward when looking at an identifier. Is this thing
    declared in this function/scope? Is it a global? Is it something

    I am a stickler for declarations and prefer to declare
    everything. As applied to JavaScript, what say you? And why?


    Gene Wirchenko
    Gene Wirchenko, Nov 29, 2011
    1. Advertisements

  2. Gene Wirchenko

    Mike Duffy Guest

    I agree 100%. In the case of Javascript, even more so.

    My coding philosophy is a bit different than most of the people here. I am
    a firm believer in learning "barely" enough. This gives me the time to
    learn barely enough about a much wider range of subjects than I could if I
    decided to become an expert at anything.

    Thus please don't take my advice too seriously. If you want a good laugh,
    just take a look at my js libraries on my web-site. Yessir! I wrote my own.
    I would advertise them here if not for the fact that they are 100% perfect
    for my utilization and about 0% for everyone else.
    Mike Duffy, Nov 29, 2011
    1. Advertisements

  3. There is no "Javascript" [1].

    However, in ECMAScript implementations like JavaScript, JScript, etc.,
    variable declarations are important:

    If you do not declare an identifier a variable, and assign to it, one of
    three things can happen: nothing (no effect at all, because an existing
    property was read-only), an exception is thrown (because an existing
    property could not be overwritten or created), or a property of the global
    object is being created or overwritten (sometimes called an "implied

    With a variable declaration, the scope of a standalone identifier is clear.

    That is why in ECMAScript Edition 5.x's Strict Mode¹, such an assignment, if
    the identifier cannot be resolved, always throws a ReferenceError exception.
    You can attempt to trigger Strict Mode with

    "use strict";

    on top of the code or function body.

    See also: <>

    ¹ not to be confused with layout engines' Standards (Compliance) Mode

    [1] <>
    Thomas 'PointedEars' Lahn, Nov 29, 2011
  4. <snip>

    It's a typing error, or is that too inconvenient for you?.

    John G Harris, Nov 29, 2011
  5. OP here. It might be inconvenient for him, but it is certainly
    convenient for me.

    It is things like that that help a person who is new to a
    newsgroup determine who gives good advice and who should be killfiled.
    Mr. Lahn quickly establish himself in the second category.

    Squawking over missing a capital in "JavaScript" is rather
    missing the point when done in a newsgroup called


    Gene Wirchenko
    Gene Wirchenko, Nov 29, 2011
  6. Gene Wirchenko

    Mike Duffy Guest

    Do not count him out too quickly. Many of the important things I have
    learned here have been authored by him. Some people here take themselves
    too seriously, but not anyone who calls himself "Pointed Ears". Take a good
    look at what he actually says. If you are beginner, a lot of the detail he
    usually goes into will probably not be interesting, but he does understand
    what he is talking about.
    Mike Duffy, Nov 29, 2011
  7. Gene Wirchenko

    Scott Sauyet Guest

    The point is not that the capital is missing. The point is that
    unlike with Ruby, C++, Java, and many other languages, there are a
    number of different implementations of ECMAScript with sometimes quite
    incompatible behavior. When speaking of "Javascript", it sounds as
    though one is speaking of the Mozilla implementation, "JavaScript",
    but usually it turns out that it is some abstract common subset of
    these implementations that is meant.

    Personally, I don't have any issue with the use of "Javascript" as a
    shorthand for an abstract ECMAScript implementation. If one
    implementation is being described, it's usually easy enough to make
    clear. For the same reason, I use "LISP" for a number of languages
    which differ IMHO quite a bit more than do the popular ECMAScript
    implementations. If I want to distinguish Allegro CL, I simply say

    Thomas Lahn often makes a point of noting this distinction, often
    rather brusquely. It seems to me mostly pedantry, but it's probably
    good to have pedants among us.

    -- Scott
    Scott Sauyet, Nov 29, 2011
  8. ^
    Edit: Add "ed".
    Manner and manners count for a lot. Some people lord their
    knowledge over others, and one has to wade through their misemotional
    data. Others are more helpful.

    My killfile of Mr. Lahn is only mark read, so I still have the
    messages should I ever need to refer to them.


    Gene Wirchenko
    Gene Wirchenko, Nov 29, 2011
  9. Gene Wirchenko

    Mike Duffy Guest

    He is not too likely to help you out in the future now that he knows you
    will not be seeing any possible responses. But if you feel that you are not
    able to contenance his style, by all means you should killfile him.

    I am curious though to know why you feel the need to tell him that you have
    done so. Thomas has never changed his style to suit the regulars, so it is
    very unlikely that he will do so for a newcomer.
    Mike Duffy, Nov 29, 2011
  10. Unfortunately, much too often it is evidence of a serious but common
    misconception. Hence my remark.

    Not with javascript. Nonsense propagates like wildfire in this field.
    -- Richard Cornford, comp.lang.javascript, 2011-11-14
    Thomas 'PointedEars' Lahn, Nov 29, 2011
  11. I had soft-killfiled him permanently already because of his clueless
    reaction, < Apparently Mr.
    Wirchenko is confusing me with someone who could take a wannabe like him
    seriously (mind you, _not_ *newbie*), and he is delusional enough to think
    that I would *lose* something by not reading his FAQs.

    (BTW, it's)

    PointedEars (F'up2 poster)
    Thomas 'PointedEars' Lahn, Nov 29, 2011
  12. Maybe, the regulars have gotten used to it -- "Grin and bear it."
    -- but maybe, my post will result in him reconsidering his manner.

    Since his posts do not appear useful, I would rather that he not
    reply to my posts. I have seen the phenomenon of a thread getting
    hijacked by other discussion and the original question never being


    Gene Wirchenko
    Gene Wirchenko, Nov 29, 2011
  13. On Tue, 29 Nov 2011 13:36:49 -0800 (PST), Scott Sauyet

    Yes, brusquely. I have also seen it done and the question not
    answered. I can be pedantic myself. Pedants can be fine, but there
    is a glut of rude pedants.


    Gene Wirchenko
    Gene Wirchenko, Nov 29, 2011
  14. Gene Wirchenko

    Scott Sauyet Guest

    That's very common on USENET, but does seem more prevalent here. As
    long as people don't mistake this discussion group for a (paid?) help
    forum, we're fine. Many of the most interesting discussions start as
    asides to existing threads.

    -- Scott
    Scott Sauyet, Nov 30, 2011
  15. It's worse than pedantry. He flatly refuses to agree that a simple name
    covering all variants would be useful. (In the same way that 'vehicle'
    covers cars, lorries, motorbikes, etc (1)).

    He will only agree to a multi-word sentence that excludes some of the
    languages that are On Topic for this news group. (Exclusion justified on
    the grounds that he doesn't want to discuss them).


    (1) Though whether something on wheels aiming to go at Mach 1.3 should
    be included is debatable.
    John G Harris, Nov 30, 2011
  16. That might well be, but I have had the situation of needing an
    answer to my question, never getting anything, and yet there is a long
    thread. I think that other people then tend to think that the
    question has been answered.


    Gene Wirchenko
    Gene Wirchenko, Nov 30, 2011
  17. Gene Wirchenko

    Tom de Neef Guest

    You must have misread. There was quite some useful info right from the
    I suggest you focus on content rather than style.

    Tom de Neef, Dec 1, 2011
  18. Gene Wirchenko

    Scott Sauyet Guest

    Again, that's very common. Feel free to restate the question, in the
    same thread or another. But remember that many users are here for the
    discussions and very few are here specifically to try to answer your
    questions. If you make the question interesting enough, you'll
    probably get a number of answers.

    -- Scott
    Scott Sauyet, Dec 1, 2011
  19. No, I prefer to focus on style. That way I get to know who posts
    in a readable, helpful style. Of those, it is almost certain that
    some will post correct information. Because their style is readable,
    it is easier to determine usefulness and correctness.

    Or I could try deciphering posts written by people who are
    antagonistic or have axes to grind.

    No, I think I will continue with the first way.

    Thank you to all of you who have posted helpfully. I like your


    Gene Wirchenko
    Gene Wirchenko, Dec 1, 2011
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.