User:Pjacobi/Draft/Nulls and undefined
< User:Pjacobi | Draft
The NULL and/or undefined values
[edit | edit source]What is the value of variables never assigned before? And: is there a special NULL value. Are they considered to be the same.
NULL
[edit | edit source]ECMAScript | Lua | Perl | PHP | Python | Ruby | |
---|---|---|---|---|---|---|
Name | null | nil | NULL | None | nil | |
Sames as undefined? | - | + | + | + | - | |
valid in boolean context? | - | + | -/- | + | + | |
valid in other expressions? | - | + | -/- | - | - |
- ECMAScript
- ECMAScript has distinct null and undefined, the latter is only for declared variables never assigned a value. Accessing undeclared variables raises an exception.
- Lua
- In Lua, the NULL value nil and the undefined state are equal. This is basically the same model as Perl, but with giving this state a name. So undefing a variable has the normal assignment syntax.
- PERL
PERL has no named NULL value but undefining a variable using undef can mostly achieve the same, as using an undefined variable in boolean context is allowed (and evaluates to false).
- PHP
- Python
- Ruby