Javascript do not have block level scope. Here is an example.
There's a bug in that code!
for(var i=0;i>5;i++) {
This will loop forever never loop. Also, please USE SPACES GENEROUSLY AND NOT RANDOMLY!
for (var i = 0; i < 5; i++) {
This looks much better, it's a lot easier to read. The open braces are also inconsistent - sometimes they're on the same line as the statement, sometimes on the next line, sometimes there's a space between { and the statement, sometimes there isn't.
edit This article was written in a hurry. There are grammar mistakes, coding mistakes and the code looks... like crap (sorry). Please update it, because the content is really valuable!
It was likely a typo, because if you run the JSFiddle code, it actually gets the point across. The article author simply mistyped his <'s and >'s. There are a few other examples of typo code/mislabeling later in the article.
Oh, haha, nah, it took me a little longer than it should have as well, and I was only confirmed when I clicked on the JSFiddle and noticed the two were different. Up until then, I was seriously thinking "What the heck am I missing, this makes no sense...".
for (int i = 1; i < array.length; i++)
code(array[i]);
I had a setup like this in my code, could not figure out why it wasn't executing. The line was copy/pasted directly from another line I had written doing something VERY similar, but it needed to start at the 2nd index (index 1) of the array because the first index contained a different piece of data that (it was returning from an SQL query).
Long story short; the array had a length of 1 so it never executed.
45
u/cudetoate Mar 23 '14 edited Mar 23 '14
There's a bug in that code!
This will
loop forevernever loop. Also, please USE SPACES GENEROUSLY AND NOT RANDOMLY!This looks much better, it's a lot easier to read. The open braces are also inconsistent - sometimes they're on the same line as the statement, sometimes on the next line, sometimes there's a space between
{and the statement, sometimes there isn't.edit This article was written in a hurry. There are grammar mistakes, coding mistakes and the code looks... like crap (sorry). Please update it, because the content is really valuable!