Multiple choice technology programming languages

What value do variables have before they are first assigned?

  1. undef

  2. null

  3. 0

  4. nil

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In Perl, variables are uninitialized (have the special value undef) until they are first assigned a value. This is different from null in some languages or numeric defaults like 0. The undef value evaluates to false in boolean context and as an empty string or zero depending on context.

AI explanation

undef is correct. In Perl, a variable that has been declared but not yet assigned a value holds the special value undef, representing 'no value.' It's Perl's own concept, distinct from null (Java/JavaScript/SQL terminology), 0 (which is a legitimate defined numeric value), and nil (Ruby/Lisp terminology). undef evaluates as false in boolean context, as an empty string in string context, and as 0 in numeric context, but it is a distinct value that defined() can detect — Perl programmers rely on this to distinguish 'never set' from 'explicitly set to zero/empty'.