What do you call double pipe in javascript, as used in this context?

People often write this to indicate default values:

var thing = this || that;

which is, AFAIK, the same as:

var thing = !!this ? this : that;

What do you call the method used to specify default values ​​in the first block of code?

NOTE . I do not ask what is called logical OR. I ask how the alternative of triple notation is called (as written in the first block of code).

+3
source share
4 answers

I would call:

var a = A || B;

conditional assignment , as it is effective:

if (!!A) {
  a = A;
} else {
  a = B;
}

and this replaces the conditional statement : ?

var a = A? A : B;

It can also be called "logical assignment" because it includes the logical expression OR, but does not seem to match its action.

+3

, .

- .

:

if ((foo = bar)) {

} else {
    foo = baz;
}

if bar. bar , null .., .


: :

. :

if ((a = b)) { ...

, :

if (a === b) { ...

. true if (b).

. , .

, ( C), .


:

if ((foo = foo)) {

} else {
     foo = baz;
}


var x = false;
console.log((x = x)); // False

, :

(x = x) || (x = y)

:

x = (x || y);

:

x = x || y;
+1

"".

-1

The double channel is the Boolean OR operator in JavaScript.

If the method had a name, I assume it will be "(ab) using the short circuit of the logical OR operator"

-1
source

All Articles