Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: How does JavaScript calculate values and in wich order?

1. ## How does JavaScript calculate values and in wich order?

Hello!

Code:
`i=y=1;i<y;`
result:false (this makes sense to me)

I´m wondering about how JavaScript does the following calculations to get those results? Please explain it if you do. I´d appreciate your time and help. Thank you!

Code:
`i=y=1;y<<i;`
result:2

Code:
`i=y=1;y>>i;`
result:0

• Have a look at

https://developer.mozilla.org/en/Jav...wise_Operators

Left shift a << b
Shifts a in binary representation b (< 32) bits to the left, shifting in zeros from the right.

Sign-propagating right shift a >> b
Shifts a in binary representation b (< 32) bits to the right, discarding bits shifted off.

What results were you expecting?

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

• The << and >> are logical shift operators (left and respectively right); they are not arithmetical operators. That means your problem has nothing to do with the order of operations

http://www.c-point.com/javascript_tu...soprlshift.htm
http://www.c-point.com/javascript_tu...soprrshift.htm

• In fact I can think of few situations where bitwise operators are of any real use in Javascript.

• I did not know what to expect. I just tried it and when i tried to figure it out my line of thought was something like this.

Code:
`i=y=1;y<<i;`
The values of "i" and "y" is set to "1". "i" is greater than greater "y". The result should still be false if that was how JavaScript interpret "<<" as.) I don´t know any practical use for this (my knowledge of programming is very limited) I was just being curious.

Now i see that it did interpret "<<" as something else.

It started with that JavaScript sets a value like this a=1, and it checks if av value is equal like this a==b then I just figured that greater than would be like this a>>b. Now i know that it is like this a>b. Then i was curious about what a>>b did.

I have no concept of what you just wrote but it helped me understand my question. Thank you!

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•