javascript question

Discussion in 'OT Technology' started by mrengc, Feb 6, 2003.

  1. mrengc

    mrengc Guest

    In the example function below, I was wondering what the scope of the 'p' array object is? Does it exist outside of this function after the function is called? When is the memory allocation released for this object?

    Secondly, in the 'd[j++] = "hello";' statement
    is "hello" assigned to index=0 and then incremented to 1 or index=1. The first question is more important. This second question I can try. But I thought I might as well ask to make sure.


    function preloadImages() {
    var j = 0;
    p = new Array();

    d[j++] = "hello";
  2. Jericho

    Jericho Active Member

    Oct 21, 2002
    Likes Received:
    I don't really know javascript but I'm pretty sure that it only exists within that function and not outside of it, as for:

    d[j++] = "hello";

    I think you meant p[j++] = "hello"; but anyway, a simple test revealed the following results:

    p[0] resulted in hello
    p[1] resulted in undefined

    that means that it's assigning "hello" to p[0] and then incrementing j to 1.

    Anyway, why couldn't you test this on your own? it takes no time at all. :confused:

Share This Page