How to write Javascript if branching by nullish or not

Asked 1 years ago, Updated 1 years ago, 244 views

Sometimes I want to make a conditional branch based on whether a value is nullish or not.
For now, I am writing as follows, but if there is a clearer way to write (specifically, I don't have to write null twice), please let me know.

 if(a??null===null){
  // do something
}

javascript

2023-01-18 09:48

1 Answers

What about a==null?The readability may not be good.


2023-01-18 10:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.