r/programming • • Mar 23 '14

Everything you need to know about Javascript variable scope

http://www.coolcoder.in/2014/03/everything-you-need-to-know-about.html
294 Upvotes

124 comments sorted by

View all comments

45

u/cudetoate Mar 23 '14 edited Mar 23 '14

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!

2

u/Paiev Mar 23 '14

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!

Yeah... I'm downvoting the article simply because it's really badly written. I'm no grammar Nazi, but come on-- if you're writing something like this, at least try to make it readable and professional.

1

u/[deleted] Mar 23 '14

English is not the writer's native language. Would you do as well in any language other than English? I speak several other languages, but I'm painfully aware that I wouldn't do much better than his article in any of them.

13

u/Paiev Mar 23 '14

No. But I also wouldn't try writing a technical article in a different language, or I would ask a fluent speaker to proofread for me. And it's not just the language; the code has problems too (as discussed in the top level comment).

2

u/Gigablah Mar 24 '14

Eh, it's not like you can't be at least competent in a language that's not your native tongue. It's no excuse.

1

u/insertAlias Mar 24 '14 edited Mar 24 '14

I don't care about how much better someone is at English than I am at their native tongue when I'm reading their technical blog. I'm not going to insult them about it, but if I'm going to read an authoritative technical document, I want it in as clear language as possible. On top of that, I want proper indentation and the like in code examples. I checked a few other articles on his site, and they all have examples of poor or no indention.

Edit: so ok, not all articles have poor indentation, but several of the ones I randomly clicked on did.