Skip to main content
Improve code formatting
Source Link
Maya
  • 5.8k
  • 1
  • 27
  • 40

Use ternary operators:

if(a == 2a==2){ some code gets executed...; code;} else { some other code gets executed...;  code;} 

can be abbreviated to this:

(a == 2 a==2? some code : some other code); 

Shorter, huh?

Use ternary operators:

if(a == 2){ some code gets executed...; } else { some other code gets executed...;  } 

can be abbreviated to this:

(a == 2 ? some code : some other code); 

Shorter, huh?

Use ternary operators

if(a==2){some code;}else{some other code;} 

can be abbreviated to this:

(a==2?some code:some other code); 

Shorter, huh?

Mod Removes Wiki by Doorknob
Corrected the name more usual in informal use ('conditional shorthands') to their official name ('ternary operators').
Source Link

Use conditional shorthandsternary operators:

if(a == 2){ some code gets executed...; } else { some other code gets executed...; } 

can be abbreviated to this:

(a == 2 ? some code : some other code); 

Shorter, huh?

Use conditional shorthands:

if(a == 2){ some code gets executed...; } else { some other code gets executed...; } 

can be abbreviated to this:

(a == 2 ? some code : some other code); 

Shorter, huh?

Use ternary operators:

if(a == 2){ some code gets executed...; } else { some other code gets executed...; } 

can be abbreviated to this:

(a == 2 ? some code : some other code); 

Shorter, huh?

Source Link

Use conditional shorthands:

if(a == 2){ some code gets executed...; } else { some other code gets executed...; } 

can be abbreviated to this:

(a == 2 ? some code : some other code); 

Shorter, huh?