from Hacker News

Ask HN: What should an undefined variable evaluate to?

by carlosneves on 9/22/24, 2:57 PM with 2 comments

I think most (all?) compiled languages evaluate to a compilation error.

As for NodeJS, I thought it would evaluate to `undefined`, but it seems to consistently throw a `ReferenceError` for version 20.

What's the result for other languages?

  • by Doctor-R on 9/22/24, 10:05 PM

    Ages ago, the Digital Equipment VAX had a hardware hack where a null pointer (value is 0) would return a 0 when de-referenced. Which is the null character, the end of a string. So most of the time operations moving characters would terminate correctly. Obviously not portable to other computers.

    In the IEEE 754 floating point definition, there are specific values for errors: mathematically undefined, division by zero, overflow, underflow, and inexact. These MUST be implemented in hardware to meet the specification.