8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

「2==1==0 → true」ワイ「!?」

Last updated at Posted at 2019-06-23

どういうことか

スクリーンショット 2019-06-24 0.25.12.png

まず最初の2項に注目します。
2==1はfalseですよね。

ということは、実際のところはfalse==0を評価することになります。
JSの==は暗黙の型変換を行うので、falseと0は等価となり、最終の結果はtrueになります。

/* こう書くとわかりやすいかも */
(2==1)==0 //true

なので、下記画像のように左側の式をどれだけ長くしようが、結果はtrueです。

スクリーンショット 2019-06-24 0.11.03.png

10==9==8==7==6==5==4==3==2==1はfalseなので、結局のところはfalse==0を評価しているだけに過ぎません。

元ネタ

Twitterで見つけたネタです。

8
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?