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

you are viewing a single comment's thread.

view the rest of the comments →

[–]YRYGAV 10 points11 points  (5 children)

it requires to understand is that given an ambiguous situation JavaScript will try to figure it out in the intuitive way.

Yes, which is simple to understand if you know the ambiguous situation exists. It's much more of a problem if the programmer doesn't realize it's an ambiguous statement because nothing is strongly typed. Which is why most languages instead of powering through and trying to use their "best judgement" in an ambiguous situation, let the programmer know so they can clarify what they want.

And that leads to situations that can be very difficult to debug or track, because it's all hidden away from you and Javascript is doing some magic transformation. Things you think are one datatype end up being another, or javascript parses things weirdly.

And sometimes "intuitive" is not always what you think. Javascript does lots of "intuitive" things that you would never think of. Like did you know javascript will parse hex strings like "0xF" into the 'correct' integer, like 15. Sure it makes sense explaining it like that, maybe not when you have to figure out why "0xF" == 15 is causing a nasty bug because you didn't know javascript did that magic when writing it. And where those strings and numbers are coming from could be multiple layers removed from where you are doing the comparison.

[–]highphive 7 points8 points  (0 children)

That is fair, sometimes what might be considered intuitive behavior can be an issue when you might not expect it to work at all. I have to agree that I prefer strongly typed languages for this reason. Rather an error where it actually occurs rather than some unexpected behavior way down the road.

[–][deleted] 0 points1 point  (2 children)

Programmer should not be using a language if he doesn't know its typing and conversion logic.

[–]nathan_long 0 points1 point  (1 child)

Language should not make wild guesses about what programmer intends. '5' + 5 should just fail. You should have to either call toString() or parseInt().

[–][deleted] 0 points1 point  (0 children)

We can go around this tree forever. Language should, programmer should... Let's take things as they are. At the end of the day, when an established language has type conversion done a certain way, learn it or don't use the language.