What does it mean "return !! userId"
This question already has an answer here:
它返回userId作为boolean
It's a boolean cast, from a fasly or truethy value to false or true respectively.
You might see:
var string = ""; // empty string is falsy
var bool = !!string; // false
falsy by the way means that it follows: myvar == false as opposed to false which follows: myvar === false (triple comparison).
Similarly truethy is myvar == true .
!!userId与Boolean(userId)相同。
上一篇: 你最喜欢的C ++编码风格成语是什么?
