koajs / kick-off-koa

[MAINTAINERS WANTED] An intro to koa via a set of self-guided workshops

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

what does these two wavy lines means in cookies chapter?

xr opened this issue · comments

commented
var n = ~~this.cookies.get('view', { signed: true }) + 1;

what does ~~ mean ? thanks

commented

UPDATED:

I searched, they are double-bitwise NOT operation, the following are some paris.

~~null;      // => 0
~~undefined; // => 0
~~0;         // => 0
~~{};        // => 0
~~[];        // => 0
~~(1/0);     // => 0
~~false;     // => 0
~~true;      // => 1
~~1.2543;    // => 1
~~4.9;       // => 4
~~(-2.999);  // => -2

Due to this.cookies.get('view', { signed: true }) is undefined when first time request to '/', so , in ~~ this way quickly transfer undefined to 0 and increase it...