JavaScript — The good, the bad, and the ugly.

Xander Reynolds
2 min readMar 26, 2021

--

Learning JavaScript has been an enlightening experience. I must admit, I was surprised by some of the qwerks of JavaScript compared to other strongly typed languages like C++, C#, & Java.

A few odd things:

  • Strange undefined behavior when something is wrong? for example, try to add a number and a string :D
  • function scope….
  • What is ‘this’? Baby don’t hurt me, don’t hurt me, no more.
  • prototypal inheritance
  • Copying an object — easy right? Not so fast
  • Comparing for equality

Also some smaller things like lack of private methods, dynamic typing, etc. I have also worked with python, so the dynamic typing was not so unfamiliar, but with these other oddities, it definitely felt like something different. This was definitely not python!

But! With learning a new language, there are always good things that come out of it. I read a book recently called 7 Programming languages in 7 week. It is a great read. The book goes through 7 programming languages and makes comparisons between different languages. The goal is not to be an expert, but to get an overview of how different languages approach the same problems. The book compares programming paradigms and starts with more object-oriented languages, some messaging-based, and then more functional languages.

There is always some good along with the bad. And in JavaScript, I found some really good things too. It makes it very convenient to loop through data with functions like

.filter(), .map(), and .reduce()

I also found the arrow functions to be compact and useful in conjunction with these methods along with others like .find(). Arrow functions are very useful, but you should know when to use them, otherwise you can also get into trouble.

The spread operator is another nice feature. If you want to take a part, the rest, or the entire array, you can do this easily with the spread operator.

Another great feature is destructuring. This allows you to take a part of an object, or array, and assign it to a variable.

From the documentation, they provided this example.

let a, b, rest;
[a, b] = [10, 20];
console.log(a); // 10
console.log(b); // 20

[a, b, ...rest] = [10, 20, 30, 40, 50];
console.log(a); // 10
console.log(b); // 20
console.log(rest); // [30, 40, 50]

({ a, b } = { a: 10, b: 20 });
console.log(a); // 10
console.log(b); // 20

// Stage 4(finished) proposal
({a, b, ...rest} = {a: 10, b: 20, c: 30, d: 40});
console.log(a); // 10
console.log(b); // 20
console.log(rest); // {c: 30, d: 40}

This is a type of pattern matching that is common in functional languages. It is a really nice way to break down information and get the information that you need.

In the future I might write some more examples about these features.

Happy Coding :)

--

--

No responses yet