Live data from Hacker News

A re-introduction to JavaScript

developer.mozilla.org

41–50 of 115 posts

Re: A re-introduction to JavaScript

#42

Very nice to see it starts off with a (correct) discussion of JS types! JS devs mostly don't know the actual types in JS, which is pretty crazy if you think about it.

I think 99% of the problems people have with Javascript are not actually types, but `this`. It's the most confusing part about Javascript. This context, var foo scope, what? Why is this value not updating? undefined? What???

and 99% of those 99% problems can easily be solved with the correct use of .bind() or .apply().

Re: A re-introduction to JavaScript

#43

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

There's definitely no point to avoid them for IE. The point as I see it is that it should be avoided for every browser. Indeed IE's users are having terrible experience anyway, but let's just don't push FF and Chrome to their memory limits, just because we don't care with our code. One of the best parts when I develop client-side web-apps is the debugging and looking close what the garbage collector is doing. For exa…

Can you expand on what you said about the `delete` keyword implications with the GC? I've never heard of that issue.

Re: A re-introduction to JavaScript

#44
post #18

The article mentions an idiom for iterating over an array. It says 'an even nicer idiom is...' and then it shows it. I just wanted to say that the behaviour of this 'nicer' idiom may not be what's expected - it stops iterating once it hits the first falsy value. I was quite excited actually when I first saw them idiom, until I quickly realized its limitations

Also seems weird that they don't mention `forEach`.

(Sure, IE<9 is a caveat, but all the Array iteration methods are the easiest things to shim and if you're targeting below IE9 chances are pretty good it's not the first shim you'd be using.)

Re: A re-introduction to JavaScript

#45

Earlier quoted context omitted.

There's definitely no point to avoid them for IE. The point as I see it is that it should be avoided for every browser. Indeed IE's users are having terrible experience anyway, but let's just don't push FF and Chrome to their memory limits, just because we don't care with our code. One of the best parts when I develop client-side web-apps is the debugging and looking close what the garbage collector is doing. For exa…

Can you expand on what you said about the `delete` keyword implications with the GC? I've never heard of that issue.

I haven't either, only that delete will cause code to be de-optimized.

Re: A re-introduction to JavaScript

#46
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

Another way to cast to a Number is the bitwise-or operator. It has the useful property of always yielding a number. '42' | 0; // 42 NaN | 0; // 0 null | 0; // 0 undefined | 0; // 0 false | 0; // 0 true | 0; // 1

It always yields an integer, so it's useful if you know you want an integer.

Re: A re-introduction to JavaScript

#47

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?

Not really. Most languages don't have a built-in decimal type, it's usually just a library feature. Higher precision floats won't help you either, as adding more decimal places won't make 0.2 == 0.3, it will just make the difference between them slightly smaller.

Re: A re-introduction to JavaScript

#48

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.

Re: A re-introduction to JavaScript

#49
post #26

Earlier quoted context omitted.

What could be more fun than a language that says the result of dividing by 0 is "Infinity"? It's a hoot!!

That's from IEEE 754 (a standard for floating-point arithmetic). `NaN` and -0 exist for the same reason.

To be fair, just because something is a standard doesn't mean it isn't a dumb implementation. Just by testing the programming languages on my computer, I can tell you that Python, C, and D all throw errors rather than allow it, which is the smart thing to do.

Re: A re-introduction to JavaScript

#50
post #18

The article mentions an idiom for iterating over an array. It says 'an even nicer idiom is...' and then it shows it. I just wanted to say that the behaviour of this 'nicer' idiom may not be what's expected - it stops iterating once it hits the first falsy value. I was quite excited actually when I first saw them idiom, until I quickly realized its limitations

Yeah and not a big fan of them saying you can do for...in on an array while casually mentioning the limitation of doing such. I would consider it far better practice to NEVER iterating over an array with for...in.

Is there even any guarantee it would be iterated in the correct order?
Post reply on HN