7

In default 'if' one line statement are two block, for true, and false:

variable ? true block : false block;

How declare 'if' with one block?

I expect something like this:

variable ? true block;
Emerceen
  • 2,395
  • 3
  • 16
  • 22

2 Answers2

8
if(variable) block;

With the conditional operator you need the false bit also.

taguenizy
  • 2,020
  • 1
  • 7
  • 25
3

You can do:

variable && block

For example:

let variable = true;
let o = variable && 3;
Nitzan Tomer
  • 139,150
  • 41
  • 299
  • 282