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.
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.
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:
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.
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.
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.
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.
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.
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
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:
2. External file (recommended for real projects)
Put your JavaScript in a separate .js file and link it with the src attribute:
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:
Download in parallel,
run after HTML is parsed
Download in parallel,
run as soon as ready
Block HTML parsing,
download & run immediately
<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).
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.
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.
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.
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.
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.
Test your knowledge
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 โ