What?! You called JavaScript Weird? Come on dude, I have using it for years, it is the best language I have ever met.
Let's have a coffee and se...
For further actions, you may consider blocking this person and/or reporting abuse
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.
1 + "23" - 10 = 113
1 + "23" takes as string concatenation operation. The results is "123". Then it subtract 13.
Still not that clear how following things works.
[] + []
{} + {}
[] + {}
{} + []
+!+[]
I thought about
+!+[]
, it could be like these (I may be wrong)I think thats the solution. It's working on console.
Some of these have got to do with associativity, coercion and auto semicolon insertion.
3>2>1 this is based on left
right asociativity of the > operator 3>2 is evaluated first, which will be true and when we evaluate true >1 it will be false coz true is equal to 1 not greater.
After a return key if the interpreter does not find anything there will be an automatic semicolon insertion and returning nothing like that in the example will be undefined. All the code below the return key would be ignored.
But the language is interestingly weird! I think we can call it WeirdScript :)
i have seen this before here destroyallsoftware.com/talks/wat i guess.
o my freaking god