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 Wikipedia 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 editor.

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 Mozilla.

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 Node and a copy of the solution.

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.

Series Navigation← Hello World in RustHello World in PHP →
Advertisements

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.