/    Sign up×
Community /Pin to ProfileBookmark

Some questions about JavaScript funtions

Hi,

I am having trouble to find information about some javascript features. I have read the javascript guide and reference at netscape.com with no luck.

They are the next:

  • Can I call functions before defining them? (I like to have the most important code at the top of the script). I tried with moz and ie and it works, but I would like to know if the javascript standard permit to do this.

  • If I am trying to use an implementation dependant object like “window”, if I write the next code:

  • [code]
    if (window) {
    window.open(‘hi.html’, ‘link’);
    }
    [/code]

    This would give an error in a navigator that doesn’t have the window object implemented? To say this in another way, the “window.open(‘hi.html’, ‘link’);” will be checked in any way to know if it is well formed?
    I know that in moz this line is not checked because there is no error in the javascript console. But this would mean that only the code on an actually executed branch statements are checked.
    I don’t have very clear how a javascript is evaluated by a javascript interpreter.

    Thanks a lot,
    IrYoKu

    to post a comment
    JavaScript

    1 Comments(s)

    Copy linkTweet thisAlerts:
    @Khalid_AliDec 06.2003 — for the first part of your question,not you don't have to declare a function (like you would in C/C++).

    The order of functions will not effect,however,make sure the if you use global variables they all must be declared at the begining of the script.

    Of course I try to write my functions in the order they are used just for readability purpose....?
    ×

    Success!

    Help @IrYoKu spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.12,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...