4 ms·
If I had to guess, it'd probably be roughly related to things like this: var x = 1; var y = 1; function methodA() { return { javascri
by icey 18y ago
If I had to guess, it'd probably be roughly related to things like this:
var x = 1;
var y = 1;
function methodA()
{
return
{
javascript: x + y
};
}
function methodB()
{
return{
javascript: x + y
};
}
(Hint: They don't do the same thing)
- spoiledtechie 18y agoAnswer?
- deleted 18y ago[deleted]
- icey 18y agomethodA returns "undefined", methodB returns an object.
- jacquesm 18y agothat's just scary. I had to go and try it just because I could not believe it, now can anybody explain to me why there is a difference here ?
- icey 18y agoIt's because of semicolon insertion. Ostensibly, this was added to the language to make it more user friendly. Instead, it's the source of a lot of bugs. Here is a decent overview: http://www.openjs.com/articles/semicolon_insertion.php http://www.openjs.com/articles/semicolon_insertion.php
- jacquesm 18y agoWhat were they smoking ? I though the auto-correcting language interpreter/compiler went out the window with Pascal, there were some pretty good reasons for it and 'automatic bug insertion' was the main one. This ought to be deprecated and exterminated.
- lacker 18y agoThe fundamental problem with javascript is that it is not simple to deprecate features and add new ones. Any javascript you write has to work on at least several IE and Firefox versions, and there is no solution for this on the horizon, besides perhaps compilers that emit javascript.
- teej 18y agoHere's another gem. Compare: (0.1 + 0.2) * 10 (1 + 2)
- sharkbrainguy 18y agowhoah... what? surely ... but ... >> (0.1+ 0.2) * 10 3.0000000000000004 >> (0.1 + 0.2 + 0.1) * 10 4 wtf is going on here? Where you would expect 0.3 you just always seem to get 0.3000000000000004 ... but then it "corrects" ... Haunted!
- sharkbrainguy 18y agoso ... it turns out that this is just a property of floating point math... weird that I've never seen that before. It behaves the same in Python and MzScheme, so I can't imagine that this is something "keeping people away" from javascript.