Click here to Skip to main content
15,888,816 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
  Forogar  10-Jan-19 6:33
professional  Forogar  10-Jan-19 6:33 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
RickZeeland8-Jan-19 10:10
mveRickZeeland8-Jan-19 10:10 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
raddevus8-Jan-19 10:22
mvaraddevus8-Jan-19 10:22 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
RickZeeland8-Jan-19 19:59
mveRickZeeland8-Jan-19 19:59 
GeneralRe: Here's a specific reason devs hate JavaScript! PinPopular
Pete O'Hanlon8-Jan-19 12:40
mvePete O'Hanlon8-Jan-19 12:40 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
raddevus8-Jan-19 14:59
mvaraddevus8-Jan-19 14:59 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
Jon McKee8-Jan-19 15:26
professionalJon McKee8-Jan-19 15:26 
GeneralRe: Here's a specific reason devs hate JavaScript! PinPopular
Ryan Peden8-Jan-19 18:07
professionalRyan Peden8-Jan-19 18:07 
Others have mentioned TypeScript, but to catch an error like this, you don't even need to go that far.

Set up ESLint with a good rule set (I like the one from Walmart Labs), and it'll scream at you if you forget to use var. Actually, with that rule set, it'll probably scream at you if you use var at all instead of let, and it'll scream at you again if you used let when you could have used const. It's a tad annoying at first, but it quickly drills good habits into you.

I love TypeScript too, but I find that sometimes, I just prefer to work in dynamically typed JavaScript over TypeScript - and when I do, ESLint helps me catch errors caused by typos and omissions. You'll need to use an editor that supports ESLint, but most of them do.

As for why the JS interpreter didn't catch this for you: you gave it syntactically valid code, and it just did what you asked it to! Laugh | :laugh: I know that's an annoying answer, but with JavaScript approaching its 25th birthday, it has lots of historical baggage and bits of the language that are probably best avoided. Hence my love of ESLint - it's a friendly pedant that reminds when when you step out of bounds.

TypeScript is also great, of course. And you can use TSLint too, to ensure your TypeScript code is as pedantically great as possible. Smile | :)
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
raddevus9-Jan-19 1:13
mvaraddevus9-Jan-19 1:13 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
Member 91670578-Jan-19 21:08
Member 91670578-Jan-19 21:08 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
raddevus9-Jan-19 1:15
mvaraddevus9-Jan-19 1:15 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
Member 107319449-Jan-19 14:22
Member 107319449-Jan-19 14:22 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
Member 91670579-Jan-19 20:55
Member 91670579-Jan-19 20:55 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
TheGreatAndPowerfulOz12-Jan-19 6:27
TheGreatAndPowerfulOz12-Jan-19 6:27 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
Jeroen_R8-Jan-19 21:42
Jeroen_R8-Jan-19 21:42 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
raddevus9-Jan-19 1:19
mvaraddevus9-Jan-19 1:19 
JokeRe: Here's a specific reason devs hate JavaScript! Pin
V.8-Jan-19 23:14
professionalV.8-Jan-19 23:14 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
raddevus9-Jan-19 1:28
mvaraddevus9-Jan-19 1:28 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
jarvisa9-Jan-19 0:09
jarvisa9-Jan-19 0:09 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
raddevus9-Jan-19 1:29
mvaraddevus9-Jan-19 1:29 
GeneralRe: Here's a specific reason devs hate JavaScript! PinPopular
ClockMeister9-Jan-19 0:32
professionalClockMeister9-Jan-19 0:32 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
raddevus9-Jan-19 1:32
mvaraddevus9-Jan-19 1:32 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
Jörgen Andersson9-Jan-19 8:12
professionalJörgen Andersson9-Jan-19 8:12 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
Thornik9-Jan-19 2:16
Thornik9-Jan-19 2:16 
GeneralRe: Here's a specific reason devs hate JavaScript! Pin
Slow Eddie9-Jan-19 3:25
professionalSlow Eddie9-Jan-19 3:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.