JavaScript !== Java

30 Aug 2022

Accidentally Learning JavaScript

My introduction to JavaScript was quite the interesting one. When I was younger I did not have much interest in programming, but I did play a concerning amount of video games, one of which being Minecraft. I wanted to make a mod for Minecraft, but to do so I first had to figure out what language Minecraft was made from. In my infinite wisdom I thought Minecraft was built from JavaScript because I saw a single JSON (JavaScript Object Notation) file in the Minecraft directory. So, I went on the standard programming self study course of Youtube tutorials and websites like freecodecamp.com. Eventually, I thought that I knew enough to create a mod for Minecraft, but it all came crashing down when it turns out, Minecraft is written in Java not JavaScript. Without wind in my sails, I put down programming for half a decade until I decided to major in Computer Science. The first language I learned was Java and now I am learning JavaScript.

What’s the Difference?

The Typing

Even though they both have “Java” in their name, the two languages are quite different. The most jarring change when I learned JavaScript coming from a Java background is that JavaScript is not a strongly typed language. This means that the data type of a variable can change. The ability for variables to dynamically change throughout the program can be useful, but, in my opinion, it often leads to unforseen bugs that may be hard to find.

The Syntax

Java
class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello world");
    }
}

JavaScript
console.log("Hello world");

Without any knowledge of either language, just looking at a simple program that prints “Hello world” to the console, it is clear that JavaScript’s readability is way better than the verbose syntax of Java. This emphasis of readability and simplicity is prevalent throughout all of JavaScript. This is especially true after the advent of ES6. ES6 added many features like the arrow function that simplifies the creation of functions to a single line or for of loops that easily lets you iterate through an iterable object like an array.

Athletic Software Engineering

The ease of syntax in JavaScript the pedagogy of Athletic Software Engineering. The main idea of Athletic Software Engineering is that you do “WODS” which are just problems that do, but there is a time limit and if you do not finish in time you get no credit. I think it is a very interesting approach to teaching software development because in the real world knowing all the concepts behind software development can only do so much if you are unable to implement it in a reasonable amount of time. The time limit forces us to ingrain these design patterns to the point where they are second nature. It also puts us into a high pressure, relatively low consequence situation that will help prime us for the real world. The grading is all or nothing, you either complete the WOD in the requisite amount of time or you don’t. As a student, I would prefer if there was partial credit, but I do understand that in the real world you need to deliver a functioning product in the requisite amount of time, there is no partial credit.

Which One is Better?

With all that said it seems like JavaScript is the clear winner because it is more readable, the syntax is cleaner and is easier to learn with no programming experience. However, Java does have some advantages. The strictness of Java can help build good programming habits that you might be able to get away with in JavaScript. Fortunately, learning Java or JavaScript are not mutually exclusive, so the real question is why not learn both?