Home >Common Problem >What does option explicit do?

What does option explicit do?

coldplay.xixi
coldplay.xixiOriginal
2020-10-29 15:11:246006browse

option The function of explicit is to declare that all variables need to be defined before they can be used. Otherwise, the program will report an error when using undefined variables. In this way, errors caused by variable name spelling and other errors can be avoided. .

What does option explicit do?

VBScript does not require explicit definition of variables, that is, variables can be used directly without definition. This is very convenient, but it is also prone to problems;

For example, first define a variable named "var9" and assign a value, but when using it below, the variable name is mistakenly written as "varg", as shown in the code below. In this way, no exception will occur when the program is executed, but This will cause the processing results to be inconsistent with expectations. We expected to use msgbox to output the value of var9, but the value of varg was output, and var9 has not been assigned a value and defaults to a null value;

What does option explicit do?

The execution result is:

What does option explicit do?

The "Option Explicit" we are going to talk about can solve the above problem. The function of "Option Explicit" is: to declare all variables, they need to be defined first can be used, otherwise the program will report an error when using undefined variables. In this way, you can avoid errors caused by variable name spelling and other errors, and "Option Explicit" can speed up the running speed of the program. It saves The time to dynamically allocate variable storage space when the program is running;

We use the code just now to fine-tune it, and add "Option Explicit" to see the effect:

The execution result is:

What does option explicit do?

The program reported an error and identified the problem with our use of variables. Therefore, when programming, it is better to add "Option Explicit" to prevent unnecessary exceptions. It is worth noting: "Option Explicit” must be placed at the top of the program.

The above is the detailed content of What does option explicit do?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn