I found some code from https://github.com/andrewgodwin
var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws";
What does 'something' ? 'something' : 'something'
means?
I found some code from https://github.com/andrewgodwin
var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws";
What does 'something' ? 'something' : 'something'
means?
It is conditional operator in javascript ref. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator
var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws";
that means:
var ws_scheme;
if (window.location.protocol == "https:") {
ws_scheme = "wss";
} else {
ws_scheme = "ws";
}
It's called conditional (ternary) operator. This operator is frequently used as a shortcut for the if statement. If the condition before the "?" is true then the value just after the "?" is assigned to the variable, else the value after ":" is assigned to the variable.
Details at: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator