Hello World in JavaScript

Hello World in JavaScript Featured Image

Once again, welcome back to another installment of Hello World in Every Language. Today, I want to implement Hello World in JavaScript, everyone’s favorite language to hate.

Table of Contents

JavaScript Background

As usual, I always start by browsing WikipediaOpens in a new tab. to learn a bit more about the language.

According to Wikipedia, a company called Netscape launched JavaScript back in 1995. During development, the language was under the name Mocha. By launch, the name was changed to LiveScript before ultimately settling on JavaScript.

Today, JavaScript is used on a large majority of websites on the internet. In fact, all of the major browsers support it, so it’s certainly made a name for itself. That said, JavaScript seems to be fairly infamous. From dynamic typing to function scoping, just about every feature seems to be up for debate.

Perhaps the biggest source of hate for JavaScript is its ubiquity. There is absolutely no way to avoid the language when you set out to build something on the web. I don’t think many developers enjoy that kind of constraint.

At any rate, JavaScript has tons of interesting features such as prototyping and delegation. In addition, like Python, JavaScript is interpreted. As a result, performance can be a bit of an issue. Regardless, the language is still as necessary as HTML when it comes to web development.

Hello World in JavaScript

As promised, we’ll take a stab at Hello World in JavaScript:

alert("Hello, World!")

Don’t believe me? Open your browser’s console (typically, CTRL + SHIFT + J) and type that in. You should see a little Hello World window pop up on on you screen. But wait, there’s more:

console.log("Hello, World!")

Try typing that in. Immediately, you’ll see Hello World printed below. How cool is that?

As it turns out, Hello World in JavaScript is really easy. Since the language is interpreted, we don’t need to worry about opening a text editor. We can simply run code live in the JavaScript console. This should be fairly reminiscent of our Hello World in Python tutorial.

Of course, the similarities pretty much end there. After all, the alert and console.log methods depend on browser support. If your browser doesn’t support these functionalities, you can always play with an online JavaScript editorOpens in a new tab..

I’m not terribly interested in learning how either of these methods work in JavaScript. However, if you are, I recommend digging into the JavaScript API by MozillaOpens in a new tab..

How to Run the Solution

While we can run the code snippets above in the browser, we can also use Node. Just grab the latest version of NodeOpens in a new tab. and a copy of the solutionOpens in a new tab..

Assuming Node is in the path, all we have to do is navigate to our new file and run the following command:

node hello-world.js

That will run the script just like Python, so “Hello, World!” should print to the console.

Sample Programs in Every Language

And, that’s it! As it turns out, Hello World in JavaScript isn’t that exciting. In fact, I find it a little frustrating that our Hello World examples are not guaranteed to work in every browser. Is there a better way to implement Hello World in JavaScript? Let me know!

Up next, I want to venture to the backend of web development with a little bit of PHP. If you recall, I’ve actually played with PHP a bit for a personal project using Laravel. Of course, I’ve also dabbled with it a bit here on WordPress, but I don’t know much about the language. Next time, I’ll dig into it a bit for my own sake.

As always, feel free to share these articles with your friends and family. If the series gets enough support, I won’t stop. Just keep sharing recommendations for the next language in comments.

Sample Programs in Every Language (44 Articles)—Series Navigation

For 100 Days of Code, I’ve decided to implement a few sample programs in as many languages as possible. Each implementation details a brief history of the language and a description of the code.

The plan for the series is to explore the major general-purpose language like Java, Python, C, C++, and C#. From there, we’ll take a look at some sample programs in web development languages like Ruby, PHP, and JavaScript. As we continue, we’ll cover proprietary languages like Swift and Objective-C. Eventually, we’ll start to tackle less popular languages like Rust, x86, and Verilog. Finally, we’ll play around with some of the esoteric languages like Brainf*ck and LOLCODE.

Who knows? Maybe the Sample Programs in Every Language series will become so popular it’ll never end. To help this series grow, consider sharing it on social media with your friends. Or, if you have a language you want to see, drop your suggestion in the comments.

Jeremy Grifski

Jeremy grew up in a small town where he enjoyed playing soccer and video games, practicing taekwondo, and trading Pokémon cards. Once out of the nest, he pursued a Bachelors in Computer Engineering with a minor in Game Design. After college, he spent about two years writing software for a major engineering company. Then, he earned a master's in Computer Science and Engineering. Today, he pursues a PhD in Engineering Education in order to ultimately land a teaching gig. In his spare time, Jeremy enjoys spending time with his wife, playing Overwatch and Phantasy Star Online 2, practicing trombone, watching Penguins hockey, and traveling the world.

Recent Posts