Empty - The Default Value of a Variable

This section provides a tutorial example on how to find out the default value, Empty, of a variable before its first assignment.

What is the default, or initial, value of a variable after the declaration and before the first assignment? The answer is: Empty.

There are 3 ways to check if a variable has the Empty value:

Here is a tutorial example on how to check the default value of a variable:

<!-- default_value.html
 - Copyright (c) 2015, HerongYang.com, All Rights Reserved.
<script language="vbscript">
   ' Variable, author, is explicitly declared
   Dim author
   document.writeln("author = " & author)
   document.writeln("IsEmpty(author) = " & IsEmpty(author))
   document.writeln("(VarType(author)=vbEmpty) = " _ 
      & (VarType(author)=vbEmpty))
   document.writeln("TypeName(author) = " & TypeName(author))

   ' Variable, buffer, is implicitly declared
   document.writeln("buffer = " & buffer)
   document.writeln("IsEmpty(buffer) = " & IsEmpty(buffer))
   document.writeln("(VarType(buffer)=vbEmpty) = " _ 
      & (VarType(buffer)=vbEmpty))
   document.writeln("TypeName(buffer) = " & TypeName(buffer))

Here is the output of this VBScript example:

author = 
IsEmpty(author) = True
(VarType(author)=vbEmpty) = True
TypeName(author) = Empty

buffer = 
IsEmpty(buffer) = True
(VarType(buffer)=vbEmpty) = True
TypeName(buffer) = Empty

The output confirms that the initial value, or the default value, of a variable is Empty, regardless of how it is declared.

Table of Contents

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

 Variant Data Type, Subtypes, and Literals

 Arithmetic Operations

 Numeric Comparison Operations and Logical Operations

 String Operations - Concatenation and Comparison

Variable Declaration and Assignment Statement

 Variable Declaration and "Dim" Statement

 Assigning Values to Variables - "=" Statement

Empty - The Default Value of a Variable

 Expression and Order of Operation Precedence

 Statement Syntax and Statement Types

 Array Data Type and Related Statements

 Array References and Array Assignment Statements

 Conditional Statements - "If ... Then" and "Select Case"

 Loop Statements - "For", "While", and "Do"

 "Function" and "Sub" Procedures

 Built-in Functions

 Inspecting Variables Received in Procedures

 Error Handling Flag and the "Err" Object

 Regular Expression Pattern Match and Replacement

 scrrun.dll - Scripting Runtime DLL Library

 Creating Your Own Classes

 IE Web Browser Supporting VBScript

 IIS ASP Server Supporting VBScript

 WSH (Windows Script Host)


 PDF Printing Version