No Result
View All Result
CloudReports
  • Home
  • Linux
  • Web development
  • Javascript
  • SQL
  • Ant Design tutorial
  • QR Code Scanner
  • Home
  • Linux
  • Web development
  • Javascript
  • SQL
  • Ant Design tutorial
  • QR Code Scanner
No Result
View All Result
CloudReports
No Result
View All Result
Home Web development

[JS] 2 == 1 = 0 is true

by npn
June 23, 2019
in Web development
Reading Time: 2 mins read
0
0
SHARES
235
VIEWS
Share on FacebookShare on Twitter
Rate this post

The other day on Twitter,@TaneoKoyama was doing an interesting tweet, so I’m going to go into this one step deeper.

console.log(2==1==0); // => true

This is really true when you try it.
interesting.

Let’s disassemble and examine one by one.

console.log(2==1); // => false

↑ At this stage, it will be false …

console.log(false==0); // => true

but this is true, it is Kimo of this code.
According to the JavaScript specification, “number 0” is false.
As a result, 2==1==0there will be situations where it becomes true.

console.log(0==1==2); // => false

The result is false.
When disassembling, it is processing ….

console.log(0==1); // => false
console.log(false==2); // => false

You can confirm that the process is being performed from the left.

ADVERTISEMENT
console.log(2===1===0); // => false

Yes, it has been false.

Difference between equality operator (==) and strict equality operator (===)

Although it is the equivalence operator “==” which is usually used casually, there was a characteristic that can be judged by type conversion.
As a result, false (boolean type) is converted to “0”, so0=0It will be judged that.

On the other hand, the strict equality operator (===) does not perform type conversion.
So false is false and 0 is 0.
In other words, even if it judges, this is not equivalent.

In the case of a similar example

console.log(null == undefined); // => true
console.log(null === undefined); // => false
console.log(0 == ''); // => true
console.log(0 === ''); // => false
  • x==y==z, it is processed from the left
  • “==” and “===” are clearly different operators.
  • Be careful about type conversion of “==” In
  • JS, 0 (numeric value), null, undefined, ” (empty character) are treated as false

that’s all.
Thank you until the end.

Tags: equality operatorJavaScriptstrict equality operator
ShareTweetShare
Previous Post

Using JavaScript to vibrate the device with a web browser

Next Post

Disable browser ‘Back’ button with Javascript

npn

Related Posts

Linux

What is the location of the MySQL databases?

April 24, 2022
604
Web development

Top 10 Best WordPress SEO themes of 2022

March 16, 2022
500
Web development

Gmail – Gmail Sign Up – Gmail Login

August 30, 2021
7.1k
Javascript

Configuring VS Code for Node/JavaScript Development

August 2, 2021
1.3k
Javascript

How does Nodejs solve the problem of high concurrency?

July 18, 2021
1.3k
Linux

How to create a self-signed SSL certificate for Apache on Ubuntu 16.04

July 18, 2021
1k
Next Post

Disable browser 'Back' button with Javascript

Discussion about this post

No Result
View All Result

Categories

  • Android (1)
  • Ant Design tutorial (7)
  • App/Game (2)
  • Javascript (16)
  • Layout and Routing (2)
  • Linux (9)
  • PC & LAPTOP (6)
  • PERSONAL FINANCES (1)
  • React (13)
  • SQL (2)
  • TECHNOLOGY & DIGITAL (7)
  • The Basics (5)
  • Web development (37)

Search

No Result
View All Result

Categories

  • Android (1)
  • Ant Design tutorial (7)
  • App/Game (2)
  • Javascript (16)
  • Layout and Routing (2)
  • Linux (9)
  • PC & LAPTOP (6)
  • PERSONAL FINANCES (1)
  • React (13)
  • SQL (2)
  • TECHNOLOGY & DIGITAL (7)
  • The Basics (5)
  • Web development (37)
No Result
View All Result
  • Home
  • Linux
  • Web development
  • Javascript
  • SQL
  • Ant Design tutorial
  • QR Code Scanner
Exit mobile version