What is Option Explicit and How to Use It? - TestingQ.com

-->Exclusive Portal for Testing Jobs

What is Option Explicit and How to Use It?

Option Explicit:
The Option Explicit statement forces the explicit declaration of all variables using the Dim, Private, Public, or ReDim statements.

This statement prevents the accidental reuse of the name of a previously declared variable. Also, if you mistype a declared variable's name or try to use an undeclared variable, an error message is generated.

Note that the Option Explicit statement must be placed at the top of the code before any other VBScript commands

Ex: Option Explicit
Dim a,b,c
a = 10
b = 20
c = a+b

VBScript in general doesn't need variable declaration. For example without using "Dim" a variable can be directly used for assigning etc.
For ex: temp=1

However, such practice can always be error prone. Ex: if i want to use the same variable in some other statement and miss spell it,say

VBScript still considers "tempe" as valid. This case if we use OPTION EXPLICIT On top of our application and proceed then application will not proceed unless until u declare each and every variable. Hence u make sure that ur variable is serving ur purpose.

To receive daily posted JOBS & Interview Questions
Just enter your email address below and click 'Submit'
Enter your email address:

Make sure to activate your subscription by clicking on the activation link sent to your email