1252748
1252748

Reputation: 15372

significance of multiple operators in one variable declaration

In this answer which tests whether or not a page has been cached, I see this variable declaration.

var isCached = currentCookie !== null;

What is the significance of the = and !== operators together in one statement?

Upvotes: 1

Views: 73

Answers (2)

Mattias Buelens
Mattias Buelens

Reputation: 20159

That snippet is equivalent with:

var isCached = (currentCookie !== null);

In other words, isCached is set to true if and only if currentCookie is strictly not equal to the null reference.

Upvotes: 2

Fabrizio Calderan
Fabrizio Calderan

Reputation: 123397

that expression means:

isCached is true when currentCookie !== null, false otherwise

you should read it like

var isCached = (currentCookie !== null)

or more verbosely is equivalent to

var isCached;
if (currentCookie !== null) {
   isCached = true;
}
else {
   isCached = false;
}

Upvotes: 2

Related Questions