I'm curious for the codes below:
Code 1:
var myValue = 10;
if(isBlocked)
myValue = 20;
Code 2:
var myValue;
if(isBlocked)
myValue = 20;
else
myValue = 10;
Both must do the same. But I prefer Code 1, as this obviously requires fewer lines. Is it better to use code 1 to assign a single value?
EDIT
Thanks guys to remind me of the "triple operator". Before closing the message, I would like to ask: "Rate the assignment", similar to "Calculate the expression else"? (Performance)
source
share