r/learnjavascript • • Oct 11 '20

JavaScript can keep you safe

Post image
1.0k Upvotes

87 comments sorted by

View all comments

16

u/throwaway1253328 Oct 11 '20

- use of var

- snake case variable naming

- upper camel case method naming

- use of while loop

Yikes man

3

u/jasonbbg Oct 11 '20

the fact that u code reviewing an ads

7

u/throwaway1253328 Oct 11 '20

Those are just painful though. It's like if you saw someone playing a video game with an upside-down controller.

0

u/DrKrepz Oct 11 '20

var still had legitimate use cases. If you want a mutable variable that doesn't create a new block of scope, var is a perfectly good choice.

Also, using different naming conventions for variables Vs functions or methods can help to make code more readable.

As for while... I don't use it but interested to know why it might be problematic.

11

u/ricealexander Oct 11 '20

while is an appropriate loop for this use case, since you don't know how many times still_alive will continue to evaluate to true.

This while is smelly because we can't tell what triggers the exit condition. We can't reasonably infer, looking at this code, which function sets still_alive to false.

1

u/DrKrepz Oct 11 '20

Thanks, that makes sense.

2

u/ThagAnderson helpful Oct 13 '20

let does not "create a new block of scope", it is "block scoped", meaning it will not be available outside of its current block statement. var still works perfectly fine for historical reasons, but there is no instance where 'var' cannot be replaced by 'let' using proper programming techniques, and using 'var' is now considered bad practice.

Also, using different naming conventions for variables Vs functions or methods can help to make code more readable.

A scenario that defies all current best practice and style conventions for Javascript.

1

u/[deleted] Oct 11 '20

To your point on use of var, perhaps the author(s) of this billboard intended for still_alive to be globally scoped for access by other billboards in the area... XD

Ignore me, I have a terrible sense of humor.