Please explain this weird javascript line

I came across a piece of code:

for(i=((90.0E1,0x5A)<=(0x158,140.70E1)?(.28,3.45E2,0):(95.30E1,26.40E1)<=1.400E2?(1,this):(108.,0x227));i<length;i++) { 
   // some other code here
} 

Can someone help me by explaining the material in for () brackets?

+3
source share
4 answers

The result of the comma operator always matters on the right side. Therefore, each pair of the form (a, b) is evaluated as b. Since in your code "a" never has a side effect, we can just omit it to get:

for(i=(0x5A <= 140.70E1 ? 0 : ...);i<length;i++) { 

"..." , : 0x5A = 140.70E1 true, ?: , .. 0.

,

 for (i=0; i<length; i++) { 

.

+5

for, , ,

i = ((90.0E1,0x5A)<=(0x158,140.70E1)?(.28,3.45E2,0):(95.30E1,26.40E1)<=1.400E2?(1,this):(108.,0x227))

?: , , , .

?:

condition ? value if true : value if false 

,

condition:      (90.0E1,0x5A)<=(0x158,140.70E1)
value if true:  (.28,3.45E2,0)
value if false: (95.30E1,26.40E1)<=1.400E2?(1,this):(108.,0x227)

-if-false ?:, , , .

+2

E-, :

for(i=((900,90)<=(344,1407)?(.28,345,0):(953,264)<=140?(1,this):(108.,551));i<length;i++)

((900,90)<=(344,1407)?(.28,345,0):(953,264)<=140?(1,this):(108.,551)) == 0;

which makes the code equivalent:

for(i=0;i<length;i++)

This is a very creative and confusing way to create a loop forand a good joke.

0
source

Source: https://habr.com/ru/post/1756423/


All Articles