How different is Python from JavaScript?

Aleksandra Borowska
09 July 2021
5 min read

This is a question I asked myself a few weeks back. I am a JavaScript developer by trade and have recently ventured into the back-end world to learn the fundamentals of Python and to identify how these fundamentals differ from those in JavaScript. So I’ve written this article to articulate some of the particular differences that stand out, and hopefully generate interest for any front-end developer looking to take on something new.

Front-end, Back-end

The most immediate difference between Python and JavaScript lay in its application, with the former more widely present in the fields of data science, AI and ML, and the latter more so for web development.  JavaScript is a scripting language best known for creating the front-end part of an application whereas Python is generally considered a tool for creating the back-end side.

Python and JavaScript Syntax

Here's another fundamental difference between Python and JavaScript: syntax. I got used to lots of curly braces and semicolons in JavaScript, however soon discovered that they don't apply in Python. Instead, Python employs indentations.   

Let’s take a look at a simple function definition comparison below. You will also notice a difference in the naming convention. JavaScript uses lowerCamelCase while Python uses the snake_case convention.

 

JavaScript vs Python: Variables

Since the ES6 release, we've been using two keywords when defining variables in JavaScript: let and const. In Python, this is not required. Instead, variable names are looked up in the narrowest relevant context and can be reassigned. Constants in Python are declared using uppercase names. Technically, you can still modify it, but the uppercase naming convention should serve as a red flag. 

Both Python and JavaScript are dynamically typed. Python is a strongly typed language whereas JavaScript is a weakly typed language

In order to check a value of a variable, you can print it out. In JavaScript, you will print something in the browser’s console. Python is a language that will print out in its own console.

Python vs JavaScript: Data Types

JavaScript has six primitive data types :  

  • String 

  • Number 

  • BigInt 

  • Boolean 

  • Undefined 

  • Symbol 

  • Null 

Python has four of them

  • Integer

  • Float 

  • Boolean

  • String 

 

In both JavaScript and Python, the data type doesn’t need to be defined when declaring a variable. 

Integers and floating-point numbers are considered as a number type in JavaScript. In Python, you cannot create a variable without assigning a value to it. JavaScript allows you to do this with such a variable having a value of undefined

If you want to represent the absence of a value in Python, you can assign None as the initial value, or null in JavaScript.

Python has four structural types:

  • List 

  • Dictionary

  • Tuple - similar to List however once assigned, you cannot change its elements

  • Set 

JavaScript structural types are:

Python vs JavaScript: Logical Operators

There are three logical operators in Python: “and”, “or”, “not” which work the same in JS, but are written differently: “&&”, “||”, “!”.  In Python, the “==”” works like the “===” operator in JavaScript.

Python vs JavaScript: Conditional Statements

Indentation is the term to remember when it comes to writing Python code. Otherwise, conditional statements are more or less similar to those in JavaScript. Let's look at the examples below:

What's interesting is how in JavaScript there is an additional control structure (called switch), whereas no such structure exists in Python.

JavaScript vs Python: For Loops and While Loops

The syntax for loops and while loops is similar in both languages, yet slightly simpler in Python:

 

In JavaScript, we also have a “for ... of” and “for ... in”  loops:

It is worth mentioning that JavaScript also has a do...while loop. This loop runs at least once regardless of the condition. There is no such thing in Python.

Python vs JavaScript: Functions

The syntactical difference between functions has already been shown at the beginning of this article. I think it’s worth mentioning that in Python the number of arguments passed to the function call has to match the number of parameters defined in the function definition. There is no such rule in JavaScript; a function can be called with fewer or more arguments than the parameters

JavaScript vs Python: Classes 

We define classes in a similar way both in Python and JavaScript. The name of a class, as well as each word in this name, starts with a capital letter. The constructor that initializes a new instance is called the __int__ keyword in Python and is then referred to with the self keyword. In JavaScript, the constructor is called with the constructor keyword and is then referred to with this keyword. 

From JavaScript to Python

I hope this brief analysis of the difference between JavaScript and Python is useful, particularly for JavaScript developers wishing to learn more about Python's main programming concepts, and for those looking to explore the varying fields in which both languages are employed. 

At Startup Development House, our leading team of programming experts works in many of these fields and regularly employs JavaScript and Python when developing the state-of-the-art software applications it prides itself on.  If you’d like to discover more about what’s behind the expertise, feel free to reach out at hello@start-up.house

Til next time!

You may also like...

Development

How to recruit a programmer

But let's get serious. As the IT industry's high-speed rate of expansion continues apace, so the demand for soft...

Aleksandra Borowska
22 October 2021
6 min read
Startups

What is greenwashing and how software can help prevent it

Since the 1990s, we’ve seen a growing demand for environmentally-friendly products that has exceeded the manufacturing proce...

Agata Bieniek
15 October 2021
6 min read