This is a floating point rounding error and is definitely not exclusive to JavaScript. It happens with basically any language that implements floats.
3 > 2
true
3 > 2 > 1
false
I also don't think this one is language specific. It should evaluate the same nearly anywhere that follows a left to right execution order for same-precedence operators.
A lot of the other stuff is solid "weird language spec" though. I especially like this one:
> ['1', '7', '11'].map(parseInt)
(3) [1, NaN, 3]
Took me a moment to remember what it was doing there and figure out the trick. The fact that there are two separate bits of knowledge required is especially neat.
yes, you are right about these ones, I am including them to just showcase some 'weird' / interesting parts in JS. some of them are not actually weird, it is weird only when comparing with other languages.
varnew_array=arr.map(functioncallback(currentValue[,index[,array]]){// Return element for new_array}[,thisArg])
If the callback accepts a second parameter, it passes the index of the element to it. parseintdoes accept two parameters, but of course, it doesn't expect an index in the third one.
This is a floating point rounding error and is definitely not exclusive to JavaScript. It happens with basically any language that implements floats.
I also don't think this one is language specific. It should evaluate the same nearly anywhere that follows a left to right execution order for same-precedence operators.
A lot of the other stuff is solid "weird language spec" though. I especially like this one:
Took me a moment to remember what it was doing there and figure out the trick. The fact that there are two separate bits of knowledge required is especially neat.
yes, you are right about these ones, I am including them to just showcase some 'weird' / interesting parts in JS. some of them are not actually
weird
, it is weird only when comparing with other languages.sorry my eye catching title is kind of misleading
I found that one interesting too. Took me some time.
I noticed that
works as expected.
parseint
is misinterpreting the second parameter somehow?Then I saw docs for Array.prototype.map.
If the callback accepts a second parameter, it passes the index of the element to it.
parseint
does accept two parameters, but of course, it doesn't expect an index in the third one.And sure enough, the output confirms my theory!
you are close, if you take a look at the api doc, you will fully understand it.
developer.mozilla.org/en-US/docs/W...
Yep! I'm aware. Pretty cool.