Site icon CXL

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:

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:

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:

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:

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:

JavaScript libraries that marketers should know include:

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

Exit mobile version