🔖
演算子小話 - !!
を見て試した。
var banana = true;
console.log(banana);
//true
console.log(!banana);
//これはfalse
console.log(!!banana);
//これはtrue
console.log(!!!!!!!!!!banana);
//これでもtrue
console.log(!!!!!!!!!!!banana);
//これでもfalse
つまり演算子重ねても普通に使える
var banana = true;
(banana == true)?console.log("boo"):console.log("hey");
//boo
(banana !== true)?console.log("boo"):console.log("hey");
//hey
(banana != true)?console.log("boo"):console.log("hey");
//hey
となるんだが
こういうことをしたら
var banana = true;
(banana !!== true)?console.log("boo"):console.log("hey");
//Uncaught SyntaxError: Unexpected token '!'
(banana !!= true)?console.log("boo"):console.log("hey");
//Uncaught SyntaxError: Unexpected token '!'
(banana !! true)?console.log("boo"):console.log("hey");
//Uncaught SyntaxError: Unexpected token '!'
(banana !=== true)?console.log("boo"):console.log("hey");
//Uncaught SyntaxError: Unexpected token '='
怒られた。
Discussion