Python vs. JavaScript
Tags: javascript, beginners, python
Published: 2024-06-03 11:57:20


  Python and JavaScript (JS) are two fairly old programming languages at this point, but what makes them different from each other? Many would consider these languages fairly beginner friendly. How are they similar? We'll go over a couple of things that set these two languages apart and why they've been in the game for so long.

## Humble Beginnings
Both languages in this post are very mature and rooted, being made in the early days of 90's public internet.
###Python
  Python was developed by _Guido van Rossum_ starting in 1989 but wouldn't be released until 1991. Funny enough according to Python Institute, the name is derived from Monty Python's Flying Circus! Python is maintained by Python Software Foundation. It was built with a couple things in mind: 

- Being easy to learn.

- Being easy to read and write.

- And being easy to obtain.

###JavaScript
  JavaScript is slightly younger, being developed in 1995 by Netscape programmer, _Brendan Eich_. Here's a fun fact, Brendan Eich built JS in 10 days! It was originally called Mocha, then LiveScript, and finally the JavaScript we all know today. In 1997, Netscape would hand off JS management and maintenance to the European Computer Manufacturers Association (ECMA). The newly handled versions would be called ECMAScript or ES. The standardized version now is ES6(2015) which added a lot of features that devs had been asking for. If we were to compare it directly to Python for comparison sake:

- Also easy to learn.

- Slightly harder to read and write.

- Also fairly easy to obtain.

---

![Tiobe Top Languages Chart May 2024](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f7fqsnen9crspgca8f3c.png)
According to Tiobe.com, Python is the most popular coding language sitting at a crazy 16.33% approval rating as of May 2024! It even won Tiobe's Language of the Year in 2007, 2010, 2018, 2020, and 2021. JavaScript, while not as high, still sits in the top 10 at number 6 with a 3.01% approval rating. It also won Language of the Year in 2014. Learning either one of these won't give you any difficulty landing a job.

---


##Let's Talk Syntax
  Python and JS are both fairly easy to write, but what are some key differences in the syntax? Python is known for its high readability, almost pseudocode-like structure. JS on the other hand is more known for it's flexibility. Here's some example syntax on how you would write some basic code in each language:

####Variables

In Python, variables aren't defined with keywords, just set them to whatever data type you need.

```
num = 10 #Python uses # for comment lines
string = 'hello' #It doesn't require semicolons to end lines
```
In JS, it is best practice to use declarative keywords, like _let_ and _const_, when making variables. Not doing so can lead to scope issues.

```
let num = 10;
let string = 'hello';
```

####Functions
Python uses the _def_ keyword to define a function.

```
def add(num1, num2): #Python uses colons to indicate new blocks
  result = num1 + num2
  print(result) #It also uses print() for printing
```
JS uses either the _function_ keyword or _arrow function_ syntax. Arrow functions give the option to shorten function blocks.

```
function add(num1, num2){
  result = num1 + num2
  return console.log(result) //JS uses console.log() for logging
}
//OR
add (num1, num2) => console.log(num1 + num2)
```

####Conditionals
Python **does not** use curly braces to define blocks like JS. Instead it uses _indentation_ to define its blocks. This changes how conditionals look of course. For example:

```
if num < 0:
  print('negative')
elif num === 0: #Python uses elif instead of JS's _else if_
  print('zero')
else:
  print('positive')
```
Here's JS's version:

```
if (num < 0){ // Here the conditions must be wrapped in parentheses
  console.log('negative')
} else if (num === 0){ //Braces to indicate code blocks
  console.log('zero')
} else{
  console.log('positive')
}
```
Just in these simple examples you can see how Python really strives to make coding faster and more readable.

Here's a video from _Red Eyed Coder Club_ that shows how a basic algorithm would be built side by side in both languages:
{% embed https://www.youtube.com/watch?v=Jld0aUQ9LZw %}

##Use Case
  Where Python and JS start to break apart from each other is each of their use cases. JS focuses more on front-end development while Python focuses more on the back-end side of things.

###Javascript
  JS is used alongside HTML and CSS a lot of the time. This means that you can find yourself building functional websites and applications on the back-end that are also pleasing to the eye on the front-end. This is reflected in the frameworks and libraries JS offers, some of the most popular frameworks being React, Vue, and Angular. If you enjoy this, that probably means you would want to go for full-stack dev positions.

###Python
 Python, being more back-end focused, is primarily used for things like scripting and automation. Its frameworks and libraries will focus more on data sciences or automation tasks. Some popular ones are Pandas, NumPy, and Scikit Learn.

  Now don't get it twisted, just because one language has a focus in one area doesn't mean that you can't use it at all for a weaker one. Just keep in mind that if you were to go that route, you may just have more trouble, or take more time trying to get things to work correctly.

##Conclusion
  So what does all of this mean? Well, when thinking about jobs or projects that you want to do, picking a language can make those projects significantly harder or easier. Python will shine working on the back-end while JavaScript will shine while working on the front-end. Neither one is necessarily a better choice over the other, it just depends on what **YOU** want to do. Most people after learning one will go and learn the other. After all, coding languages are just tools, and having different tools will make you more desirable as a new hire.


###Sources Used
- [The History of JavaScript](https://www.springboard.com/blog/data-science/history-of-javascript/)
- [Brendan Eich](https://en.wikipedia.org/wiki/Brendan_Eich#:~:text=He%20completed%20the%20first%20version,was%20named%20JavaScript%20in%20December.)
- [About Python](https://pythoninstitute.org/about-python#:~:text=Python%20was%20created%20by%20Guido,called%20Monty%20Python's%20Flying%20Circus.)
- [W3Schools](https://www.w3schools.com/python/python_syntax.asp) For Python syntax 
- [Tiobe Index](https://www.tiobe.com/tiobe-index/)
- [Tech With Tim on Youtube](https://www.youtube.com/watch?v=t9CAFYn7YgY)