Comment

Comment by orange8

> You can't avoid null and undefined

We are speaking about just null, not "null and undefined". Believe it or not, I simply do not use null in JS. Study the concept of "truthy and falsy" in JS.

> Accessing a missing property or method results with undefined. Hope you remember the exact method names and field names of all objects in your codebase!

I don't. I do however structure my code predictably, using consistent naming conventions and patterns. I hope you do realize JS existed for over 20 years before TS, and complex apps like gmaps and google docx were built entirely in JS.

> Using "str".match(regex) results with null if there are no matches.

const match = /bar/.exec("str");

if( match ){

  // am only interested in what happens if foo returns a *truthy* result.
 
  // The exact type of a falsy result is irrelevant, it either matches (truthy) or it doesn't (falsey)

}
parent orange8 6 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton