What is JavaScript?

JavaScript is the language of the web. Every website you visit โ€” Google, YouTube, Amazon, Jumia โ€” uses JavaScript to make pages interactive. Buttons that respond to clicks, forms that validate input, animations that catch your eye โ€” all JavaScript.

It was created by Brendan Eich in 1995 at Netscape Communications in just 10 days. Originally called Mocha, then renamed to LiveScript, and finally JavaScript โ€” a marketing decision to ride the hype around Java, which was popular at the time.

Common misconception: JavaScript is NOT related to Java. They are completely different languages. The name was a marketing trick by Netscape to attract Java developers. Think of it like "car" and "carpet" โ€” similar name, totally different things.

Today, JavaScript is the most popular programming language in the world according to Stack Overflow surveys, GitHub statistics, and every major developer report. It runs in every web browser, on servers, in mobile apps, and even on IoT devices.

๐Ÿ›’
UrbanCart Example
JavaScript powers everything you see on UrbanCart

Imagine you're building UrbanCart, an e-commerce store for tech gadgets and lifestyle products. When a customer clicks "Add to Cart," JavaScript handles that click. When the cart total updates without reloading the page โ€” JavaScript. When search suggestions appear as you type โ€” JavaScript. When the checkout form validates your email โ€” JavaScript.

By the end of this track, you'll build the full UrbanCart experience from scratch.

A brief history of JavaScript

JavaScript has gone from a quick browser hack to the foundation of modern web development. Here are the key milestones:

1995 โ€” The Birth

Brendan Eich creates JavaScript at Netscape in 10 days. Originally called Mocha, then LiveScript, then JavaScript. It was designed to make web pages interactive โ€” a task HTML alone couldn't handle.

1997 โ€” ECMAScript Standard

JavaScript is submitted to ECMA International for standardization, becoming ECMAScript (ES). This ensures all browsers implement the same language. The spec is called ECMA-262.

2005 โ€” AJAX Revolution

AJAX (Asynchronous JavaScript and XML) lets web pages fetch data without reloading. Gmail and Google Maps demonstrate the power. The era of "Web 2.0" begins.

2009 โ€” Node.js

Ryan Dahl creates Node.js, bringing JavaScript to the server side. For the first time, developers can use one language for both front-end and back-end. This changes everything.

2015 โ€” ES6 / ES2015 (Modern JS)

The biggest update in JavaScript history. Introduces let/const, arrow functions, classes, template literals, destructuring, modules, promises, and more. This is the "modern JavaScript" you'll learn in this track.

2020s โ€” Full-Stack JS

React, Next.js, Express, and TypeScript dominate the industry. JavaScript is now a full-stack language: front-end, back-end, mobile (React Native), desktop (Electron), and even machine learning (TensorFlow.js).

Where JavaScript runs

JavaScript runs in two main environments. Understanding this distinction is key to understanding the full-stack landscape.

๐ŸŒ

Browser (Client-Side)

Every web browser โ€” Chrome, Firefox, Safari, Edge โ€” has a built-in JavaScript engine. Chrome uses V8, Firefox uses SpiderMonkey. In the browser, JavaScript can:

  • Manipulate the DOM (add, remove, change HTML elements)
  • Handle events (clicks, scrolls, key presses)
  • Create animations and transitions
  • Fetch data from APIs (AJAX/fetch)
  • Store data locally (localStorage)
๐Ÿ–ฅ๏ธ

Node.js (Server-Side)

Node.js takes Chrome's V8 engine and runs it outside the browser. On the server, JavaScript can:

  • Build web servers and APIs
  • Read and write files
  • Connect to databases (PostgreSQL, MongoDB)
  • Process payments and send emails
  • Run background tasks
Full-stack JS: This is why JavaScript is so powerful โ€” you can use the same language for both the front-end (what users see) and the back-end (server, database, APIs). In this track, you'll master both sides.

Adding JavaScript to HTML

There are three ways to add JavaScript to an HTML page. Let's look at each one.

1. Inline script (inside HTML)

Place your JavaScript inside a <script> tag directly in the HTML file:

index.html Inline JavaScript

2. External file (recommended for real projects)

Put your JavaScript in a separate .js file and link it with the src attribute:

index.html External script file

3. defer vs async

When the browser hits a <script> tag, it pauses HTML parsing to download and run the script. This can slow down your page. Two attributes fix this:

defer
Download in parallel,
run after HTML is parsed
async
Download in parallel,
run as soon as ready
No attribute
Block HTML parsing,
download & run immediately
Best practice Use defer for most scripts
Best practice: Either put your <script> tag at the bottom of <body> (so HTML loads first), or use defer in the <head>. Both ensure users see the page before scripts run. For this track, we'll use the bottom-of-body approach.

Your first JavaScript

Let's write some JavaScript. There are three common ways to output data:

console.log() โ€” Developer output

Prints to the browser's developer console. This is your primary debugging tool. Users don't see this โ€” only developers do (press F12 to open DevTools).

console.log() Your #1 debugging tool
Console output
Hello, JavaScript! UrbanCart is ready 42 30 Price: 2999

alert() โ€” Popup dialog

Shows a popup box to the user. Useful for quick debugging but annoying in production. Don't use it in real apps โ€” it blocks the page.

alert() Popup message (avoid in production)

document.write() โ€” Write to the page

Writes HTML directly into the page. Simple for learning, but never used in real apps because it overwrites the entire page if called after loading.

document.write() Write directly to page (learning only)

Try it yourself โ€” console.log

Type console.log("Welcome to UrbanCart!") in the editor below and click Run to see the output. Try logging multiple values, numbers, or math expressions.

โœ๏ธ Try It Yourself โ€” Console Output
Output

Sneak peek โ€” Variables

In the next lesson, you'll learn all about variables. But here's a quick taste. A variable is a container that holds a value โ€” like a labeled box in a warehouse.

variables_preview.js A quick look at let and const
Console output
UrbanCart Max items: 50 Items in cart: 3
Coming up next: In Lesson 02 (Variables & Data Types), you'll learn the difference between let, const, and the old var. You'll explore strings, numbers, booleans, null, undefined, and more.

Try it yourself โ€” Display on the page

This time, let's put text on the actual page instead of just the console. We'll use document.getElementById() to find an HTML element and change its content. This is called DOM manipulation โ€” you'll master it later in the track.

โœ๏ธ Try It Yourself โ€” DOM Manipulation
Preview

Test your knowledge

Question 1 of 5
Who created JavaScript, and in what year?
Question 2 of 5
What does the "defer" attribute do on a script tag?
Question 3 of 5
What major event happened in 2009 that expanded JavaScript beyond the browser?
Question 4 of 5
Which of these is the best way to output debugging information in JavaScript?
Question 5 of 5
Is JavaScript related to Java?
0
/5
Great job! You're ready for JavaScript.
Africa & India's Best AI Academy
๐Ÿค– AI-first ๐ŸŽ“ Placement Assistance

You just wrote your first JavaScript.
Now build a full-stack career.

Join the Best AI Programs โ€” three 5-month courses, fully online, with placement assistance. Week 1 is free.

Explore our AI-era courses โ†’