Python vs JavaScript

Wednesday, September 9, 2020

https://cxl.com/wp-content/uploads/2019/09/image3.png

Both languages are very good, but what should you use for what, and why? That’s what i will be discussing in this post. I’d like to thank ZaphireHacks for bringing this up, i already had this debate before, but i think it’s important to have it again.

I will be rating JS and Python with 3 points, which are:

  • Performance
  • Functionality
  • and Difficulty

First, i think it’s important to define what we mean by Python and JavaScript, because for some points, the language itself can’t just define that because there are multiple implementations.

For Python, it will be cPython, the official implementation of Python. For JS, it is going to be the NodeJS runtime, using the V8 JIT Compiler, also present in Chromium based browsers. The version of Python will be 3.8 and the version of NodeJS will be 14.9.

Performance

For performance, JS clearly wins. The V8 JIT Compiler is very fast, making JS a super fast language. Obviously, it’s not as fast as a language like C, but it’s faster than Python or PHP.

Functionality

For this one, it really depends on what you are doing. JS is more suited for web related work even though it can be used for almost anything. You can even make mobile apps (React Native) and desktop apps (Electron) with it. Python can be used for almost anything as well, although it’s not as good for mobile and desktop apps. It’s also way better for writing scripts to automate actions, and is used widely in machine learning since the best libraries for that are available there.

Difficulty

In terms of difficulty, it also depends. In general, people say Python is easier than JavaScript but i don’t agree with this. For some cases, JS is way easier than Python, specially for asynchronous tasks and event driven tasks. Python definitly has an easier syntax, but in practice JS might actually be easier for you. It really depends on what you are using it for.

# Some Python code
for i in range(1, 101):
  print("We are at", i)

// Some JavaScript code
for (let i = 1; i < 101; i++)
  console.log("We are at " + i);

So, what is the best one?

As i said before, it really depends on what you are doing. However, if you are doing some web related work, you should definitly use JS, and if you are doing some machine learning or data science, you should use Python.

codingpythonjavascript

My Experience With Endeavour OS

Welcome to my blog!