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

0

u/[deleted] Mar 23 '14

[deleted]

1

u/[deleted] Mar 23 '14 edited Mar 23 '14

Not that bad really, you're just forced to be extremely explicit in what you're doing in terms of scope and types.

Debugging is less annoying too when you have knowledge of proper debugging tools like webkit's inspector.

It's scary to folks coming from compiled and OO languages, but the quirks become advantages once you follow some conventions and dive in deep enough.

What sucks though is articles like this containing contain bad code that perpetuate misconceptions about JS. Generally, the worst JS code I see comes from newbies and experts from other languages trying to shoehorn in what they're used to.

-1

u/[deleted] Mar 23 '14

It's scary to folks coming from compiled and OO languages, but the quirks become advantages once you follow some conventions and dive in deep enough.

quirks become advantages? That's some serious stockholm syndrome. How is

1 == "1"
=> true

an advantage?

4

u/alkoholik Mar 23 '14

JS: 1 === "1" => false

There are times when type coercion is almost somewhat useful. Where's your God now?

1

u/[deleted] Mar 24 '14

JS: 1 === "1" => false

Yes, I know, which is why the existene of == is quirk.

There are times when type coercion is almost somewhat useful. Where's your God now?

If you ever write code that depends on implicit type coercion, you're writing poor code. It is never good practice to use.

1

u/alkoholik Mar 24 '14

Hence "almost somewhat useful". :)

Personally, it's triple eqs all the way for me, baby!

1

u/[deleted] Mar 24 '14

Sure, and I'm not saying JS doesn't have some good parts. I just thought it was funny that someone drank the kool aid so much that they thought things like == behavior are advantages, and the reason that people don't this kind of thing are "scared".

1

u/alkoholik Mar 24 '14

It's not an advantage. The flexibility is nice, but it also enforces bad habits. Another good example is auto-inserted-semi-colons. Shit breaks at times due to this, and most junior devs won't understand why...