Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

null is not a very good default value in most cases though, since the operations you do with values of "real" types will not work on null. Therefore actually using your "default" value is pretty much guaranteed to be a bug, identical to using an uninitialized variable.

It would be better to just error out and not allow the uninitialized usage at all, but unfortunately that's not possible in Javascript.



That's the point though. I can easily do a null check to handle whether or not to process/use the value.

For instance, if I'm fetching some data I usually want to initialize the data variable as null for a couple of reasons.

1) null is not truthy, empty arrays and objects are

2) It shows that the variable is supposed to be filled, unlike undefined




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: