Option Explicit statement 
Author Message
 Option Explicit statement

Does JScript have anything like the Option Explicit statement in VBScript?


Wed, 25 Aug 2004 14:18:31 GMT  
 Option Explicit statement

Quote:

> Does JScript have anything like the Option Explicit
> statement in VBScript?

No.

You can test to see if a specific variable has been declared, but you can't
force the requirement.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use of
this email address implies consent to these terms. Please do not contact me
directly for assistance. If your question is worth asking, it's worth posting.



Wed, 25 Aug 2004 14:24:48 GMT  
 Option Explicit statement
The nice thing about JScript vs. VBScript is that JScript will complain if
you try to use a variable that hasn't been defined. VBScript by default will
just create it for you with no complaint, and that behavior is what makes
Option Explicit so essential to VBScript programming.


Quote:

> > Does JScript have anything like the Option Explicit
> > statement in VBScript?

> No.

> You can test to see if a specific variable has been declared, but you
can't
> force the requirement.

> --
> Dave Anderson

> Unsolicited commercial email will be read at a cost of $500 per message.
Use of
> this email address implies consent to these terms. Please do not contact
me
> directly for assistance. If your question is worth asking, it's worth
posting.



Thu, 26 Aug 2004 05:34:22 GMT  
 Option Explicit statement
Well...not quite. JScript will allow you to make assignments to undeclared
variables (at which time they fall into the global namespace), but balks when
you attempt to reference variables that are both undeclared and unassigned. Note
this example:

    var var1
    var2 = someValue
    if (var1) doSomething()
    if (var2) doSomethingElse()
    if (var3) doSomethingElseEntirely()

Assuming var1, var2 and var3 are all undeclared prior to this block, only the
last line will produce an error.

Quote:

> The nice thing about JScript vs. VBScript is that JScript will
> complain if you try to use a variable that hasn't been defined.
> VBScript by default will just create it for you with no
> complaint, and that behavior is what makes Option Explicit so
> essential to VBScript programming.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use of
this email address implies consent to these terms. Please do not contact me
directly for assistance. If your question is worth asking, it's worth posting.



Fri, 27 Aug 2004 07:59:55 GMT  
 Option Explicit statement
Hello,

There's no such statement in JScript.

Hope this helps.

Regards,
Max
==========================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

|Newsgroups: microsoft.public.scripting.jscript
|Subject: Option Explicit statement

|
|Does JScript have anything like the Option Explicit statement in VBScript?
|



Sat, 28 Aug 2004 14:14:44 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. <% Option Explicit %>

2. Option Explicit / use strict 4 JS

3. JScript equivalent to 'Option Explicit'?

4. Option Explicit Behavior Change

5. Option Explicit

6. Option Explicit not working

7. OPTION EXPLICIT not working

8. Option Explicit?

9. BrowseForFolder and option explicit

10. Option Explicit problem

11. OPTION EXPLICIT

12. Option Explicit Problem

 

 
Powered by phpBB® Forum Software