What's wrong with such a ternary operation?

A simple way to determine the replacement string is that there seems to be nothing wrong with it, so that if the state is empty or the default is "online", the result is that "online" is still output when the state is "offline".

var state = optionsEntity.state;  //state"offline" 
var states = function(state){
    return state == "" ? "online" : (state=state||"online");
};
    console.log(states());  //"online" 

is it because of such a nested error in ternary?

Mar.12,2021

var states = function(state){  // state
    console.log(state)  // undefined
    return state == "" ? "online" : (state=state||"online");
};

correct calling posture console.log (states (state)) / / offline

if you have the answer above, just remove the parameters in function. Simply explain, because the state you define outside is a global variable, while the parameter in function is a local variable. When function executes, it will first find the internally defined variable, and then look outside. Here, if you change the parameter name to something else, which is not the same as the outer name, the output will become normal offline

.
var states = function(state){
    return state == "" ? "online" : (state=state||"online");
};
Change

to

var states = function(){
    return state == "" ? "online" : (state=state||"online");
};

console.log () has no value passed, console.log (states (state))

Menu