View Full Version : Variables that donīt exists in the code

05-08-2006, 08:51 PM
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:


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. :D

05-08-2006, 08:53 PM
undefined is the ecma script standard for undefined variables. So browsers SHOULD give you the same result.

Always test though.

05-08-2006, 09:22 PM
Wow, i didnīt know about this ecma specification. Looking their documentation, it should answer some of my questions.

Thanks :D

05-08-2006, 10:34 PM
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.