In some programming languages an implicit declaration is provided the first time such a variable is encountered at compile time or run time error. In other languages such a usage is considered to be a fatal error, resulting an a diagnostic being issued.
Examples of how various programming languages respond to undefined variables are given below. Each code example is followed by an error message (if any).
CLISP (GNU CLISP 2.35):
*** - EVAL: variable X has no value
C (GNU GCC 3.4):
foo.c: In function `main':
foo.c:2: error: `x' undeclared (first use in this function)
foo.c:2: error: (Each undeclared identifier is reported only once
foo.c:2: error: for each function it appears in.)
Error: x is not defined
Source File: file:///c:/temp/foo.js
ML (Standard ML of New Jersey v110.55):
val y = x;
stdIn:1.9 Error: unbound variable or constructor: x
Unbound value x
Global symbol "$x" requires explicit package name at foo.pl line 2.
Execution of foo.pl aborted due to compilation errors.
Traceback (most recent call last):
File "foo.py", line 1, in ?
x = y
NameError: name 'y' is not defined
NameError: undefined local variable or method `x' for main:Object
VBScript (WSH 5.6)
(3, 1) Microsoft VBScript runtime error: Variable is undefined: 'x'