A re-introduction to JavaScript
41–50 of 115 posts
Re: A re-introduction to JavaScript
#42Very 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???
Re: A re-introduction to JavaScript
#43I 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…
Re: A re-introduction to JavaScript
#44The 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
(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
#45Earlier 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.
Re: A re-introduction to JavaScript
#46> 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
Re: A re-introduction to JavaScript
#47Earlier 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?
Re: A re-introduction to JavaScript
#48I 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 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
#49Earlier 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.
Re: A re-introduction to JavaScript
#50The 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.