No Result
View All Result
Cloud Reports
  • Home
  • Linux
  • Web development
  • Javascript
  • SQL
  • Ant Design tutorial
  • PC & Laptop
  • Technology & Digital
  • Home
  • Linux
  • Web development
  • Javascript
  • SQL
  • Ant Design tutorial
  • PC & Laptop
  • Technology & Digital
No Result
View All Result
Cloud Reports
No Result
View All Result

[JS] 2 == 1 = 0 is true

npn by npn
June 23, 2019
in Web development
Reading Time: 2min read
A A
0

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

READ ALSO

Javascript developer should stop for … in for now

Javascript developer should stop for … in for now

December 31, 2020
18
How to display colors (color, bgcolor) in console.log () for javascript developers!

How to display colors (color, bgcolor) in console.log () for javascript developers!

January 22, 2021
11
console.log(2==1==0); // => true

This is really true when you try it.
interesting.

Let’s disassemble and examine one by one.

ADVERTISEMENT
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.

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

npn

Related Posts

Javascript developer should stop for … in for now
Javascript

Javascript developer should stop for … in for now

December 31, 2020
18
How to display colors (color, bgcolor) in console.log () for javascript developers!
Javascript

How to display colors (color, bgcolor) in console.log () for javascript developers!

January 22, 2021
11
What is Unit Test? Introduction and Example about Unit Test
Web development

What is Unit Test? Introduction and Example about Unit Test

December 24, 2020
6
Accelerate your Continuous Integration pipelines with Directed Acyclic Graph (DAG)
Web development

Accelerate your Continuous Integration pipelines with Directed Acyclic Graph (DAG)

December 22, 2020
3
The FUNDAMENTAL model for learning Web Development.
Web development

The FUNDAMENTAL model for learning Web Development.

December 21, 2020
19
UTM Google, know everything to better use them!
Web development

UTM Google, know everything to better use them!

December 18, 2020
8
Next Post

Disable browser 'Back' button with Javascript

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Categories

  • Android (1)
  • Ant Design tutorial (7)
  • Javascript (21)
  • Layout and Routing (2)
  • Linux (3)
  • PC & Laptop (53)
  • React (17)
  • SQL (2)
  • Technology & Digital (152)
  • The Basics (5)
  • Web development (38)

Search

No Result
View All Result
No Result
View All Result
  • Home
  • Linux
  • Web development
  • Javascript
  • SQL
  • Ant Design tutorial
  • PC & Laptop
  • Technology & Digital