Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2006
    Location
    São Paulo, Brazil
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Variables that don´t exists in the code

    Hi, folks.

    Take a look in this situation: i want to see the value of a variable that do not exists in the script, like the example below:

    Code:
    <script>
        alert(size);
    </script>
    if i run this, the browser will show "undefined" on the alert window.
    correction: the Internet Explorer, at least, should display this on the screen.

    But what about the others browsers?? Anyone know if the value "undefined" is given to all the things that was not declared in the code? Opera, Firefox, Netscape, they should give the same result??

    Thanks for the answers.
    ----
    As coisas mais simples são as mais importantes.
    ---------
    Thompson M1A1: D-Day
    ----------------

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    undefined is the ecma script standard for undefined variables. So browsers SHOULD give you the same result.

    Always test though.

  • #3
    New Coder
    Join Date
    Mar 2006
    Location
    São Paulo, Brazil
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow, i didn´t know about this ecma specification. Looking their documentation, it should answer some of my questions.

    Thanks
    ----
    As coisas mais simples são as mais importantes.
    ---------
    Thompson M1A1: D-Day
    ----------------

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    The ECMAScript specification isn't really written with the programmer as the target - it's written for those programming ECMAScript engines, in highly technical lingo. So, unless you're experienced with that type of documents, I would advice you to search information elsewhere, for example in the JavaScript documentation and references on devmo.

    For this case though:

    - The engine will search the local scope for any variables bound using a with or within a function body. It will then search the global object(-s). If not found, it will create a new temporary variable. Variables are by default set to undefined, so all variables that have not been initialized will contain that value. If you are writing to this temporary variable, the engine will make it into a real variable in the global scope.
    Last edited by liorean; 05-08-2006 at 09:39 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •