...

/

JavaScript Program Structure

JavaScript Program Structure

Start your journey with a “Hello World” in JavaScript, learn its syntax, and compare it with Python.

This course builds on your fundamental knowledge of Python programming, introducing you to JavaScript. We’ll start with the basic structure of a JavaScript program, using simple examples to illustrate key concepts and drawing comparisons with Python to make your transition easier.

Anatomy of a JavaScript program: Hello World

One of the most fundamental tasks in computer programming is creating a program called “Hello world!”. This program is very simple and straightforward, which makes it a great starting point for newbies. Compared to more intricate programs, troubleshooting “Hello world!” is a breeze; the only difficult part is adhering to the rules in writing code. To simplify this concept, let’s examine the difference between the “Hello world!” program in Python and JavaScript.

print "Hello world!"
console.log("Hello world!");

Now, let’s see these in both languages:

Python

In Python, it’s as easy to print “Hello world!” as:

Press + to interact
print("Hello, World!")

JavaScript

Let’s see how we can print “Hello world!” in JavaScript:

Press + to interact
console.log("Hello, World!");

In JavaScript, console.log is used to print messages to the console. The semicolon ; at the end of the statement is optional but recommended for clarity and to avoid potential issues.

Challenge

Now, it’s time for a challenge. Write a JavaScript program that prints your ...