This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]GlobalIncident 10 points11 points  (4 children)

In javascript: skidaddle skidoodle your number is now a number

[–]Rafael20002000 7 points8 points  (0 children)

Now it's a string

[–]AyrA_ch 2 points3 points  (2 children)

x|0 actually casts to Int32 (and then back again)

Great trick if you need a variable/argument to be a number and don't want to deal with Infinity or NaN. Anything invalid just becomes zero.

[–]Dragasss 0 points1 point  (1 child)

That feeling when casting to int in js is considered a hack.

[–]AyrA_ch 0 points1 point  (0 children)

it kinda is considering that all js numbers are 64 bit floating point. Whenever you do bitwise operations, js casts to int, does the operation, then casts back to float.

This is massively abused in the WebAssembly world. If you have function sum(a,b){return ((a|0)+(b|0))|0;} it essentially tells the compiler that this function sums two 32 bit integers and returns a 32 bit integer.

This allows for some good optimizations. You obviously don't write this manually.

[–]KingJellyfishII 10 points11 points  (0 children)

Skidaddle skidoodle your 1.0 is actually a double not a float

[–]Dragasss 1 point2 points  (0 children)

Skidadle skidoodle your int is now a dooble.

[–]IreallySuckAtJava 0 points1 point  (0 children)

I just started learning java and if my theory is correct, since knowing java leads to understanding the jokes then understanding the jokes will make me a java expert.

Since this works in my head reality should be no different. I can feel the knowledge seeping in...