score:20

Accepted answer
render() {
    return (
      <div>
        <div>{!!(this.myvar)?this.myvar:"whatever you want"}</div>//
      </div>

    );
  }

!!: check for undefined, null, and empty value

score:6

The provided solution runs afoul of eslint's no-extra-boolean-casts rule.

An alternate method that makes eslint happy would look like this:

render() {
    return (
      <div>
        <div>{!this.myvar ? "whatever you want" : this.myvar}</div>//
      </div>

    );
  }

Related Query

More Query from same tag