Why JavaScript Sucks (as a first language)

I will not have this be a sequel that I never write!

Read part 1 here.

Last spring, my girlfriend took a Beginning Web Development class. This was her first formal computer programming class, and as a part of this class she “learned” Javascript.

I say “learn” because the class was largely self-service: the professor put up a website with “lessons” that were to be followed each week. I accept that this is the way that online classes are supposed to work, but it seemed to me that there was a lot of copy-pasting commands and code from one place to another. For example, the first week setup included:

  1. Homebrew
  2. GitHub
  3. NodeJS and NPM
  4. BrowserSync
  5. Visual Studio Code and “recommended” plugins

Woah! That’s a lot! And there was no introduction to other concepts related to computing – even questions that most may assume they know the answers to should be answered definitively so everyone is on the same page, such as:

  1. What is a file? How are files stored on disks? What is the purpose of a file system?
  2. What is a plaintext file and how is it different from a Microsoft Word document? How can they be edited?
  3. What is an operating system?
  4. What advantages does a terminal offer over a graphical user interface?
  5. What is a Git repository? How does Git store information about the repository?
  6. What is the Internet and how are web pages made? What is a web server?

To technical audiences, these questions may sound stupid – but I have spoken with many people – some of whom were my peers at UMD – and I think it makes sense to use questions like these as a baseline for beginners1.

In my last post I created a list of criteria for a successful programming learning environment:

  1. Easily accessible
  2. Friendly user interface and user experience (UI/UX)
  3. Quality documentation
  4. Low effort, high cool

So what is it about Javascript that makes it a bad choice for learning as a first language? Let’s take a look.

Easily Accessible

Admittedly, Javascript has a head start here. The language is embedded in an ecosystem of open-source projects, and furthermore, essentially everyone has an industry-standard interactive Javascript environment readily at their fingertips without even knowing it: their web browser.

The problem I see here is that virtually anything more complicated than

console.log("Hello world!");

requires a lot of boilerplate like setting up HTML files to interact with or knowing what a web server is (or at least why it doesn’t work when you send your friend a link to file:///Users/mitchell/Desktop/My%20Cool%20Program.html )

Why should a beginner have to worry about creating a view in HTML just to run their code? If you want to learn computer programming, it should be you and the program with as few layers of separation as possible, including having to create a view. That can come later! Even in simple Javascript programs that are not even using anything complicated like NodeJS and NPM, there is a lot of background knowledge at work – or, perhaps, rote memorization masquerading as background knowledge.

Friendly UI/UX

Visual Basic may have been a clunky language, but the development environment was amazing. In about 30 seconds, I could create a window, add a button, add some code to make a popup when the button is clicked, and start the debugger. And that was a fully-featured program!

mmotelvb6
I made a whole MMORPG in VB6 without ever leaving the IDE! Well, MORPG: Mostly-Online Role Playing Game

You could make the case that Javascript is the same way, but let’s be real: the best Javascript IDE is Visual Studio Code (ironically enough) and that is “just” a text editor. It has a debugger, but in my experience it’s not super easy to get up and running. Furthermore, its Node integration is a bit confusing – not the plug-and-play that it could be. Finally, it has no GUI designer – when a new programmer is faced with designing a site, it may be discouraging that their site does not look as good as the “pros” right away2, and the only way to get it to that point is to write out the HTML yourself.

Quality Documentation

Javascript has a ton of great documentation, and a ton of crappy documentation. This is not a problem unique to Javascript and I’m not going to pretend that there is a magical fantasy language that only has good documentation available for it.

What Javascript does not have is any “definitive” resource. If I have a question about Ruby on Rails, I can go to the Rails Guides section of their website and quickly find an example with something I need to get going. But if I have a question about Javascript, sometimes I’m not even sure what to Google first. Like, hypothetically3, if I am writing unit tests for React Javascript code and I want to know more about the test framework’s standard “expect” assertion, I Google “javascript expect” and I get results for Jest, Jasmine, Chai, Mocha, and whatever other Javascript framework has fallen out of vogue. Why do you need so many test runners??

It’s not really the Javascript community’s fault, but it bothers me that the go-to solution to any problem appears to be to create your own library to fix it. Oh, also, making your build scripts fully-executable Javascript files which could themselves have complex business logic is only going to make your build process less clear and harder to debug. But, maybe that’s just my own inexperience talking.

Low Effort, High Cool

This, I think, is the biggest lose for Javascript: so you set up Visual Studio Code, npm, node, the whole shebang – you settle on a expressjs, run the generator, and bam – done. Now what? You have a blank site, but you want to make a cool site with a chat app and e-commerce, or maybe just take user input – at least something Web 2.0. But to do that, you’ll have to wade through documentation, see examples, maybe bolt together a few pre-made samples you find. I’m not saying that programming is or should be all that easy, but the learning curve for Javascript is really steep and it’s hard to see your progress on something as you make it.

Conclusion

To be clear, I use Javascript for both personal and professional projects and there are some things that I really like about it: I like its flexibility, I like its lack of type safety and the I like the community around it (sometimes.) But it’s also quite frustrating trying to teach someone a language whose paradigms are completely different from those that got me interested in computers in the first place: I can understand why it would be frustrating to program in Javascript and lack the immediate feedback that the IDEs of my youth gave me!

Ultimately, my advice for aspiring software engineers would be to set aside Javascript at first and learn a few things from an environment that better suits their interests. If you have to, get an older computer and I will send my old, terrible Visual Basic code to learn from! The majority of computing concepts can be taught just as well on QBasic as on C++, and going forward I think that the Javascript ecosystem would do much better with an environment that supports learners as I, and many others, were supported by other environments.

  1. One of the best classes I took in college was a Computer Security class that did exactly this: it taught security by teaching computer and programming principles from the ground up. Yes, by that time I had been using Linux terminal commands for the better part of a decade but I still learned a lot, and I am sure the rest of the class appreciated it too!
  2. Visual Basic solved this problem by, of course, making everything look equally crappy.
  3. Not at all hypothetical, this happened to me today actually. And yes, I did know that I was using Jest, but I still had trouble finding docs for the exact version I had.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.