Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript one line If, only state true [duplicate]

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;
like image 656
Emerceen Avatar asked Sep 14 '16 10:09

Emerceen


2 Answers

if(variable) block;

With the conditional operator you need the false bit also.

like image 69
taguenizy Avatar answered Oct 24 '22 05:10

taguenizy


You can do:

variable && block

For example:

let variable = true;
let o = variable && 3;
like image 3
Nitzan Tomer Avatar answered Oct 24 '22 06:10

Nitzan Tomer