Live data from Hacker News

A re-introduction to JavaScript

developer.mozilla.org

81–90 of 115 posts

Re: A re-introduction to JavaScript

#81

I think there's no point trying to avoid memory leaks in older versions of IE. Circular references due to closures are too common and it's not worth messing with your code. IE users are probably used to getting a horrible user experience anyway. I'm sure they can cope with a few browser freezes/crashes every once in a while - They know how to take a beating :p

The reason this is mentioned (and things like the part about caching array length in your for loop) is that this tutorial was mostly written back in 2006, when things were obviously a bit different with JavaScript. The article has gotten updates since then (check the history), but not many and not to the extent it probably needs. Not sure why it keeps getting linked.

Since you seem to have an understanding of what is wrong with it, care to tell about everything you know that should be updated?

Re: A re-introduction to JavaScript

#82

Earlier quoted context omitted.

Is not a JS only thing, investigate how floating point values work.

Well other languages often offer decimal, or higher precision floats, right?

Yes, .NET is a good example with a decimal type with:

Approximate Range -> (-7.9 x 1028 to 7.9 x 1028) / (100 to 28)

Precision -> 28-29 significant digits

https://msdn.microsoft.com/en-us/library/364x0z75.aspx

Re: A re-introduction to JavaScript

#83

Earlier quoted context omitted.

Is not a JS only thing, investigate how floating point values work.

Well other languages often offer decimal, or higher precision floats, right?

Yes, .NET is a good example with a decimal type with Approximate Range -> (-7.9 x 1028 to 7.9 x 1028) / (100 to 28) Precision -> 28-29 significant digits

https://msdn.microsoft.com/en-us/library/364x0z75.aspx

Re: A re-introduction to JavaScript

#84

Earlier quoted context omitted.

They have to. There's a bug in the JavaScript spec that makes you do this :-) they are perfectly correct in doing what they are doing, if they didn't then funny thing would start to happen. Sad, but true.

Uh, what's the reason for the downvote?

Probably because when you editorialize in your comment, you may get an adverse reaction.

Re: A re-introduction to JavaScript

#85

Earlier quoted context omitted.

Especially when you need to do something like: var that = this;

That's not generally necessary in ES6 when you use "=>" to define functions. Javascript is getting better...

What happens when you nest anonymous functions? Would you have to use the arrow operator at every level?

Re: A re-introduction to JavaScript

#86
post #12

> You can also use the unary + operator to convert values to numbers: + "42"; // 42 > [...] However the "+" operator simply converts the string to NaN if there is any invalid character in it. Being a bit pedantic here, why not recommending the Number function which may be less obscure for beginners? Number("42"); // 42

Because Number(...) uses more bytes on the wire.

Re: A re-introduction to JavaScript

#87

Earlier quoted context omitted.

They have to. There's a bug in the JavaScript spec that makes you do this :-) they are perfectly correct in doing what they are doing, if they didn't then funny thing would start to happen. Sad, but true.

Uh, what's the reason for the downvote?

Perhaps that the reason for that is not some "bug" in JS?

Re: A re-introduction to JavaScript

#88
post #12

> You can also use the unary + operator to convert values to numbers: + "42"; // 42 > [...] However the "+" operator simply converts the string to NaN if there is any invalid character in it. Being a bit pedantic here, why not recommending the Number function which may be less obscure for beginners? Number("42"); // 42

Number() also converts to NaN if it's not a number though I would still avoid the + operator here because it is code smell (looks like you forgot your variable to concat).

Number automatically accepts exponent notation and auto-converts to hex (ignoring octal). parseInt() auto-converts hex and octal unless a radix is specified, but it also ignores the remaining non-number characters at the end of the string.

There isn't a single method that does whatever you want.

Post reply on HN