this.setState({
isConnected: Boolean(weAreConnected)
})
If you want to be super obvious, and aren't using a type system. this.setState({
isConnected: Boolean(weAreConnected)
})
If you want to be super obvious, and aren't using a type system. this.setState({ isConnected: !!weAreConnected }) bo-tab(
is only two more characters :)which only applies if you're writing code for yourself. you can't expect everyone to know that idiom. same with using the + operator to cast to number, or an extreme case, the tadpole operator https://blogs.msdn.microsoft.com/oldnewthing/20150525-00/?p=...
Code should be written so that it is understandable by other professional programmers, not people who started programming two weeks ago.
People who only start coding for two weeks can't understand any code.
People who start has enough experience to work, but only start in this project for two weeks, will understand "!!" idiom.
> I would leave a note to a student for using this to be honest - too unclear, and (as this thread denotes) not well known enough to put in production worthy code.
You've done a total disservice to your students that understood negative unary operations then. Given how many upvotes my initial post on this thread has (currently 38) I don't think the thread denotes what you think it does at all.
The '!!expr' is the idiom most people use whenever the need for a canonical 0/1 representation arises.