1

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?

Community
  • 1
  • 1
1252748
  • 14,597
  • 32
  • 109
  • 229
  • The significance? One sets a value (=), one determines what the value is (!==, strict inequality). The same as any other assignment operation, like "a = 42 + 69". – Dave Newton May 31 '12 at 14:26

2 Answers2

2

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;
}
Fabrizio Calderan
  • 120,726
  • 26
  • 164
  • 177
2

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.

Mattias Buelens
  • 19,609
  • 4
  • 45
  • 51