Explain execution flow of following complex javascript return statement -
i've found hard follow execution flow of return statement. if explain how execution flows work , better if can explain whats pros , cons of creating such complex statements rather more readable multi-line statement appretiate.
return option = option ? option : {}, typeof option.xvalue == "boolean" && (_ready = option.xvalue), option.name && _ready == !1 && log(option.name + "(" + option.caller + " ) api not ready.", "e"), _ready
the expression uses comma operator multiple statements, , short-circuit operation of &&
operator if
expression.
you can write code as:
if (!option) { option = {}; } if (typeof option.xvalue == "boolean") { _ready = option.xvalue; } if (option.name && _ready == false) { log(option.name + "(" + option.caller + " ) api not ready.", "e") } return _ready;
the advantage of writing single complex expression is single complex expression. reason wanting might make code harder read, or perhaps shorter.
Comments
Post a Comment