DEV Community

Discussion on: The Difference Between Null and Undefined in JavaScript

Collapse
 
blindfish3 profile image
Ben Calder

Generally is seen as a bad practice to use both

That's the first time I've heard this. Do you have any evidence to back this up?

To my mind the distinction between the two is quite clear:

  • undefined: no value has yet been assigned
  • null: explicitly set to empty

In practice I agree they're interchangeable, but occasionally it's useful to be able to distinguish between a value that hasn't been set and one that has been explicitly emptied.