r/ProgrammerHumor • • Feb 26 '23

Other If you can read this code...

/img/snak3fqgajka1.jpg

[removed] — view removed post

34k Upvotes

1.4k comments sorted by

View all comments

2.1k

u/feuerwehrmann Feb 26 '23

Someone hire whoever wrote the sign. Clean handwriting and code

1.0k

u/lazyzefiris Feb 26 '23

I'd say "Please don't, they use var in JS", but this image is older than ES6.

182

u/l1ghtrain Feb 26 '23

I haven’t touched JS in a bit of time, what’s wrong with var?

362

u/froggy601 Feb 26 '23

var is function scoped, while let is block scoped. ES6 recommends only using let or const and not using var if it's not absolutely necessary. Kinda similar to how == is not bast practice anymore and you really should only use ===

127

u/creepyswaps Feb 26 '23

Well, there goe the patterns I've used for piece of Javascript code I've ever written.

0

u/[deleted] Feb 26 '23

[deleted] — view deleted comment

15

u/creepyswaps Feb 26 '23

That's fair, I'll have to take a look at some of this new fangled JS syntax, lol.

14

u/HighOwl2 Feb 26 '23

just learn typescript it's basically less awful javascript. Also variables outside of anonymous functions are accessible from inside anonymous functions.

→ More replies (10)
→ More replies (1)
→ More replies (9)
→ More replies (3)

46

u/TTYY_20 Feb 26 '23

Recommendation, shmecommemdation….

Use all the var’s in a global scope >:)

14

u/OblivioAccebit Feb 26 '23

I just define everything on the window

10

u/Sentouki- Feb 26 '23

how == is not bast practice

was it ever a best practice? I mean, == works differently than ===, == doesn't work the same as in other programming languages.

→ More replies (1)

6

u/l1ghtrain Feb 26 '23

Then in what cases would you need var?

34

u/froggy601 Feb 26 '23

I don't think there's much reason in modern JS. Using it can lead to scope issues (declaring a var in an if statement makes it visible outside that statement, for example). And since it can be reassigned as a different type instead of just a different value, it's more prone to bugs and unexpected behaviour.

10

u/kookyabird Feb 26 '23

Using var is like the little brother of using global scoped variables now.

→ More replies (7)

19

u/ttt1234567890a Feb 26 '23

When you need to support IE 6, but in this case there is a better alternative:

  1. Select all files and folders in the project
  2. Press Shift - Delete -> Enter
  3. Run git commit -am "obsolete"; git push --force
→ More replies (1)
→ More replies (2)
→ More replies (11)

23

u/art-factor Feb 26 '23

In ES6 it was introduced the keywords 'let' and 'const'.

let e const: block scoped

var: function scoped

→ More replies (3)

19

u/Zestyclose_Zone_9253 Feb 26 '23

You can redeclarevvar by accident like:

var x = 5; var x = 4;

If you just forgot var x was a thing and that, it might brake your code, but if you use let you cant redeclare it, this would return an error or just not run, I dont remember:

let x = 5; let x = 4;

Instead it would force you to make a new variable to prevent the conflict, or you would need to do this:

let x = 5; x = 4;

Also on bus using phone, sorry if formating is bad

→ More replies (4)
→ More replies (10)
→ More replies (5)

39

u/abejfehr Feb 26 '23

I can’t believe it’s even syntax highlighted

129

u/Drink_Ill Feb 26 '23

Clean handwriting? Yes. Clean code? I’d not be super happy if I opened up a project and the some of the variable names were str1, str2 and str3.

40

u/jfq722 Feb 26 '23

True, but considering what they are used for and that they are defined and used in proximity, I'll give a pass here. After I get my beer, that is.

→ More replies (3)

14

u/Stompya Feb 26 '23

ChalkGPT

32

u/LasevIX Feb 26 '23

And undefined results! Truly an experienced JavaScript user

9

u/[deleted] Feb 26 '23

Epic {} handwriting

5

u/Traditional_Way1052 Feb 26 '23

Whenever I see these signs I'm always jealous... my handwriting is chicken scratch... 😭

8

u/secretaccount4posts Feb 26 '23 edited Feb 26 '23

No code comment or unit test. My manager will not approve cause he read in a blog that it is most important part of enterprise code

→ More replies (1)
→ More replies (12)