JavaScript to Python 🐍

Milan Parmar
2 min readJan 24, 2021

--

JavaScript to Python

I recently applied for a software engineering role and instantly received a response, asking me to take on a code challenge. Now, the programming languages I am familiar with are Ruby and JavaScript, specifically JavaScript when tackling code challenges on LeetCode, HackerRank etc. However…their email read: “Our interview challenge is in Python — if you don’t know Python, that’s OK! The challenge is about testing how you solve problems, not how well you know Python.” 👀

They kindly gave 2 links to pick up python syntax and how things function. As I only had about 2 days to do my test, I had to quickly read up on those sources and try a few code challenges using Python.

So, what did I learn going from JavaScript to Python?

Numbers

JavaScript only has numbers which could either be a whole integer or a decimal. In Python, we have three types of numbers: Int, Float and Complex Numbers.

#Int
108
#Float
2334.45
#Complex number
9879jx

Variables

In JavaScript, we have three keywords when writing variables: var, let & const but in Python we don’t need any keyword.

// JavaScript - Convention is to name variables using camelCasevar sayHello = "Hey!"
let randomNum = 5
const bye = "Bye"
# Python - Convention is to name variables using snake_casesay_hello = "Hey!"
random_number = 21
bye = "adios!"

Arrays & Lists

Python does not have in-built support for Arrays like JavaScript but Lists, the closest thing to arrays for Python, can be a work around for implementing arrays in Python. Python also makes use of tuples which are immutable, while Lists are mutable.

Code blocks

This takes some time getting used to, as there is indentation to count for in Python. A block of code in JavaScript is defined by using curly braces {}, whereas Python uses indentation.

// JavaScript loopfor (i = 0; i < example.length; i++) {
//some code
}
# Python loopfor i in example:
# some code (indented)...Yes that is basically it for Python! Nothing else is required.

Also to end a statement in Javascript we use ; but for Python we just go to a new line.

Dictionaries

Python makes use of dictionaries, or you may know them as hash tables, which are in-built however, JavaScript has no provision for built-in hash table support in any form.

There are many more differences and also some similarities between these programming languages and as my journey goes on, I will learn more and share more of these comparisons.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Milan Parmar
Milan Parmar

Written by Milan Parmar

Software Engineer 👨🏽‍💻 | Full Stack Web Development 💻 | Smartphone Tech Enthusiast📱

No responses yet

Write a response