fbpx

JavaScript vs. Python: Which Should Marketers Learn?

javascript vs python logos

Like many marketers, you may fantasize about the amazing things you could do if you learned to code. But before you get there, you need to decide which language to learn.

Several languages come up: Python, SQL, Bash, JavaScript. But only two are full-fledged programming languages—JavaScript and Python. If you’re interested in programming, these are the two languages that you should compare.

Deciding between the two should be based on:

  1. Your specialty;
  2. Your willingness to learn;
  3. Your interest in other fields.

This article discusses the pros and cons of JavaScript and Python to help you determine which one you should go for.

Let’s start with the most important question: What’s your “T”?

“T,” as in your T-shape. Depending on your specialty (the vertical bar of your T), you may gravitate toward one language or the other.

Your deepest expertise should align with where each language excels.

Python for data and automation geeks

Python is a better fit for marketers who specialize in data analysis and visualization. Python has a complete set of tools that make it ideal for data science, math, machine learning, and data visualization

Here are some practical marketing use cases for Python:

  • RFM modeling. Segment customers into groups based on their behavior with RFM  (Reach, Frequency, Monetary) modeling. With RFM, you can set a mini-goal for every segment and target each group with its own message. Here’s a guide to creating an RFM model in Python.
  • Cohort Analysis. Google Analytics’ Cohort Analysis report is limited to one cohort type (Date of Acquisition). Using python, your can create any cohort you want and get insights into what drives customers back to your product.
  • Replace manual Excel work. Your day-to-day involves some, maybe a lot, of spreadsheet work. You can save time and effort by working with data sets directly in Python. You’ll automate the work and avoid the need to export and crunch numbers in Excel or Google Sheets.
  • Automate repetitive tasks. Automate work while learning Python.
  • Predictive analytics. Build a predictive customer lifetime value model in Python.

JavaScript for SEO, PPC, CRO, and analytics

JavaScript is a better fit for many other specialities. Marketers interact with JavaScript all the time, whether they like it or not (as you’ll see in the examples below). It’s also the most widely used programming language—by a longshot.

Specialists in PPC, SEO, CRO, and product marketing benefit heavily from learning JavaScript. 

Here are some problems JavaScript can help you solve:

The bottom line: JavaScript is great for almost any digital marketer but lacks advanced data science tools; Python is ideal for marketers specializing in data and automation.

If you’re still not sure which language is right, there are three other factors to take into account: 

  1. Learning curve;
  2. Versatility;
  3. Support.

1. Learning curve: Which language is easier to learn?

I learned both languages from scratch at different stages of my life. For me, JavaScript was harder to learn. 

Learning JavaScript

Initially, JavaScript seems easy because it runs on the browser. To see JavaScript in action, all you have to do is open the JavaScript console and start writing code.

For example, most of you probably know that you can use Inspect Element to edit elements on a web page, but instead of doing that, write this in the console:

document.body.contentEditable=true

That’s not just some cool trick—it’s JavaScript accessing the Document object that represents the page and using one of its properties to change the way the page behaves.

But JavaScript becomes complex pretty fast, especially compared to Python. Since JavaScript is first and foremost a client-side language, it puts the user first and the developer second.

For example, let’s discuss Asynchronous JavaScript. Here’s a piece of code you may recognize:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async
src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-139561223-1', { 'optimize_id': 'GTM-XXXXXX'});
</script>

This is a Google Optimize script. To let Optimize make changes on your site, you must put it in the <head> of your document. Now, let’s say we’ve created a basic headline test. What exactly is going on under the hood?

  1. The browser fetches the web page and executes each line.
  2. The Optimize tag is read and a JavaScript function requests information on the changes the variant should make to the page.
  3. The page continues to go through the lines and loads the page.
  4. A response comes back from the server with the necessary changes.
  5. The headline suddenly changes to the test version.

That’s the annoying flicker effect. That’s also why Google released the anti-flicker snippet. The snippet keeps the page blank until the Optimize data is returned.

In some cases, it’s necessary to mitigate the flickering since the JavaScript snippet is running asynchronously. While it fetches data, it continues to run and loads the rest of the page (until it receives the new version and alters the UI).

You may find the flicker effect annoying, but what if JavaScript weren’t asynchronous? Imagine you had a bug in your setup, and you couldn’t get data from the server. Your page would never load, and the user would never come back. 

Asynchronous JavaScript is a pain point when writing code because it requires additional syntax. You have to state explicitly that the script should wait for a result, or else everything breaks. And it’s not the only hurdle.

Here are some core concepts that you have to learn to really “get” JavaScript:

  • The event loop, which explains Asynchronous JavaScript.
  • JavaScript scope. This is a tricky subject, but once you get it, you’re on the right track. Hoisting is the part people usually have trouble with.
  • Frameworks/Libraries (e.g., React, Node.js). You don’t have to learn frameworks, but to understand the power of JavaScript, you need to know why they’re used.
  • Object-oriented programming in JavaScript, the “this” keyword, functional programming…

It’s not super easy. But once you get it, it’s as powerful and amazing as programming gets.

Learning Python

Python, on the other hand, takes a bit longer to set up. You can’t run Python in the console, and you can’t make alterations to the front end to get by as a hacker. To install Python, you also need to do a bit of reading (depending on your system).

But Python is clean, readable, forgiving, and easy to learn. You can read a Python script like it’s written in English. Check out the code from this article on how to scrape tweets:

import requests
 from bs4 import BeautifulSoup
 all_tweets = []
 url = 'https://twitter.com/TheOnion'
 data = requests.get(url)
 html = BeautifulSoup(data.text, 'html.parser')
 timeline = html.select('#timeline li.stream-item')
 for tweet in timeline:
     tweet_text = tweet.select('p.tweet-text')[0].get_text()
     print(tweet_text)

This is just beautiful.

Using Requests (an HTTP request library) and Beautiful Soup (a web-scraping library), the author was able to scrape and print tweets with eight lines of code.

JavaScript can do that by using the console or Node.js. Here’s a similar post about achieving the same result in Node.js and Cheerio. This is the code:

const request = require('request');
 const cheerio = require('cheerio');
 var URL = "https://twitter.com/hashtag/photography?src=hash";
 request(URL, function (err, res, body) {
    if(err){
       console.log(err);
    }
    else{
       let $ = cheerio.load(body);  //loading content of HTML body
       $('li.stream-item').each(function(index){
          var tweet = $(this).find('p.tweet-text').text();
          console.log(tweet);   //tweet content
       });
    }
 });

JavaScript just isn’t as elegant. But it gets better once you get used to it. It may even “force” you to understand more about how the web works, which is a good thing.

But Python really is nice to look at.

The bottom line: JavaScript has a steeper learning curve.

2. Versatility: Which language can you do more with?

Both Python and JavaScript can be used to achieve many things, but JavaScript is more versatile.

As I mentioned, JavaScript is in everything—from your website to your script tags. It’s responsible for the UI, but it can also run on the back end with a library called Node.js.

In addition to using it for CRO, PPC, SEO, etc., you can use JavaScript for many other things that directly impact marketing campaigns:

  • Build super-fast landing pages with Gatsby.js. Gatsby.js makes your landing pages as fast as technologically possible. Check out Impossible Foods. Imagine your landing pages had the same loading speed. 
  • Scrape any website without going through an API (and make the data accessible via a web page). Both Python and JavaScript let you automate repetitive tasks, but JavaScript also lets you set up a web-based UI. Creating the front end in the same language makes your tool more accessible and flexible. Here’s an example of how I scraped Product Hunt and created a list of upvoters along with their Twitter data.

    More recently, I built a script that automates content research. Using JavaScript, I added a front end and turned the script into a product, available online for free. The tool finds hundreds of top influencers, blogs, and authors in any field, all from just a keyword. Using JavaScript, I could build and release the entire app.

Python’s versatility comes from its advantage in data science. While more niche, Python’s machine learning, statistics, and automation tools provide a relatively easy-to-use and comprehensive data-science playground, which JavaScript lacks. 

For example, Python has a package manager called Anaconda that lets you install a complete data-science suite on your computer. Libraries like Pandas and NumPy cover any number-crunching need you’ll ever face. And libraries like scikit-learn let you use machine learning to run predictions based on existing data.

The bottom line: JavaScript is more versatile—unless your needs focus on number crunching.

3. Support: Which language has the strongest communities and libraries?

JavaScript is the most popular programming language in the world, so the community is larger, but Python’s community is huge and active, too.

Both JavaScript and Python have “package management” tools. These tools help you add external libraries to your project with a few clicks. JavaScript’s most popular package manager is npm; Python’s is pip

Python libraries

Python has high-quality libraries, some of which are better than current JavaScript alternatives (especially in data visualization and web scraping/automation).

Here are a few Python libraries that marketers should know about:

  • Pandas. Python’s go-to library for data analysis—Excel on steroids.
  • scikit-learn. Machine-learning library for prediction and segmentation.
  • Beautiful Soup. Python’s most widely used web-scraping library.
  • Requests. HTTP requests made simple.
  • Matplotlib and Seaborn. Data-visualization libraries to use with Pandas.

JavaScript libraries (and frameworks)

JavaScript has way more libraries. It also has frameworks. Those frameworks have been instrumental to its growth and popularity. Frameworks define the application design and provide a set of tools to simplify, improve, and organize how we program.

Some of the most popular frameworks include:

  • React, Angular, Vue. (React is actually a library but is used like a framework.) These frameworks improve the way we build our application’s front end.
  • Node.js. Node.js is a back-end framework that makes it possible to run JavaScript code outside the browser. It’s an important milestone that makes JavaScript the only language to support front- and back-end development.

JavaScript libraries that marketers should know include:

  • Cheerio and Puppeteer (by Google). Web-scraping/automation libraries for Node.js.
  • Gatsby. The next WordPress (with the help of some other tech). Gatsby will make your site so much faster that simply switching to Gatsby can be a CRO or SEO win.
  • D3 and Chart.js. Data visualization libraries for JavaScript.
  • For other relevant libraries, check out this npm search.

The bottom line: Both JavaScript and Python have active communities and plenty of libraries to support your work.

Now that you have an idea of which programming language is right for you, here are some resources to kick start your programming quest.

JavaScript resources

Python resources to get you started:

Conclusion

JavaScript and Python are both amazing programming languages. Learning either will make you a better marketer.

While JavaScript is a good fit for any digital marketer, its shortcomings—a steep learning curve and limited data-analysis capability compared to Python—should be taken into account when considering the two.

At that same time, JavaScript is central to the modern Internet and can help you customize tracking, automate paid campaigns, and diagnose SEO issues.

I hope that this article helps you understand where—and how—to get started.  

Related Posts

Join the conversation Add your comment

  1. Awesome article, Dan! Thanks for all the useful info and resources. Having these kinds of technical skills can be very valuable for marketers. You’ve motivated me to continue learning JavaScript. Thanks man!

  2. I’m glad you’re found the article useful Marcus, if you ever need help with your JS journey feel free to hit me up!

  3. I learned python through a couple of courses in university, at this point as a marketer I really wish they taught be Javascript instead. It’s a Swiss army knife of a programming language, I can’t wait until I can take a break from content creation and dive deep into learning it. It’s not something I want to be “lukewarm” about learning.

  4. I am definitely on the Python side. It is a simple language and allows you to do a lot – from application design to working with databases and analysis. Are you interested in science? In the article, the author gives good sources. I would add one more – the Vertabelo Academy. I did courses with them myself and I am very pleased. Especially that their prices are lower than those of competitors. I would recommend!
    http://bit.ly/2oeSkjI

Comments are closed.

Current article:

JavaScript vs. Python: Which Should Marketers Learn?

Categories