Sitemap
Press enter or click to view image in full size

Introduction to JavaScript

3 min readNov 27, 2023

--

JavaScript is a high-level, interpreted scripting language that has gained widespread usage and is an essential tool for web development. It was developed by Netscape Communications Corporation, Mozilla Foundation, and ECMA International. It’s easy to learn and implement and allows developers to enhance web pages to provide an immersive user experience.

Getting started with JavaScript is straightforward, all you need is a text editor to write your code and a browser to display the results of your JavaScript code. In terms of browsers, JavaScript is supported by all modern browsers like Chrome, Firefox, Safari, and Opera.

Fundamentally, JavaScript allows you to interact with the user, control the browser, change document content, and manipulate the HTML elements in real-time. That makes it more than a language; it’s a tool that’s used to build interactive websites and web apps.

Before diving into JavaScript, it’s necessary to understand that it shouldn’t be confused with Java language. Despite their names, JavaScript and Java are two distinct languages, fundamentally differing in their design, functionality, and use-cases.

Now that we know what JavaScript is, let’s see an example! Crafting a “Hello, World!” example is a simple, traditional way to introduce any programming language:

console.log("Hello, World!");

In this code snippet, `console.log` is a function in JavaScript that writes a message to the console. When this code is run, it will print the string “Hello, World!” on the console.

Another approach to output in JavaScript which can directly interact with HTML is `document.write`:

document.write("Hello, World!");

In this example, “Hello, World!” is written directly to the HTML document.

Get Zach Landis’s stories in your inbox

Join Medium for free to get updates from this writer.

It’s worth noting that we enclose the text we want to display in quotes. In JavaScript, we can use either single quotes (`”`) or double quotes (`””`), both will work fine.

However, JavaScript is not limited to printing out text; it is also capable of complex tasks, like calculations:

let x = 5;
let y = 2;
let z = x + y;
console.log(z); // Outputs 7

In this code, we declare two variables using the keyword `let`, assign them two numbers, add those numbers together, and store the result in a third variable. Then we output the result using the `console.log`.

In the future articles of this series, we will delve deeper into variables and more complex data types and functions in JavaScript.

Finally, let’s discuss including JavaScript in an HTML document. You can write your JavaScript code inside HTML using `<script>` tags, or you can write your JavaScript in a separate file and then link that file in your HTML document. Here’s an example of using inline JavaScript:

<!DOCTYPE html><html> 
<body>
<h2>My First JavaScript Program</h2>
<script> document.write("Hello, World!"); </script>
</body>
</html>

And here’s an HTML document linked to an external JavaScript file:

<!DOCTYPE html><html> 
<body>
<h2>My First JavaScript Program</h2>
<script src="myscripts.js"></script>
</body>
</html>

The benefit of using external JavaScript files is that it makes your code cleaner, more maintainable, and reusable across multiple HTML files.

In conclusion, JavaScript is a versatile and popular language for web development, providing a way to add interactive functionality to your websites. This was an introduction to the language and there’s a vast amount we’ve yet to uncover. In the upcoming parts of this series, we will delve into more detailed aspects of JavaScript, like understanding variables, data types, arrays, objects, and much more exciting features. Stay tuned!

--

--