re: 😲🤯The most outstanding new feature in Javascript you need to know about: Optional Chaining VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Good question! Example time! const user = { auth: { isLoggedIn: false } } const isLoggedIn = user.auth?.isLoggedIn || true // is...
 

Could also consider converting to a true/false value with:

const isLoggedIn = !!(user.auth?.isLoggedIn)

@joshua I was literally going to say the same thing.
I fail to see the point/usefulness of the '??' operator

There are always alternatives if you can also write

if(user.auth?.isLoggedIn === true){
    // user is logged in!
}

Nobody is forcing anybody to use the ?? operator but I think it just fits nicely together with the ?. and makes the intent clear if the developer knows how both of them work.

code of conduct - report abuse