JavaScript 1 🧬 JavaScript Introduction
JavaScript is a versatile, interpreted programming language that powers interactivity and dynamic behavior on the web. It’s one of the three core technologies of the World Wide Web — alongside HTML (structure) and CSS (presentation).
┌─────────────────────────────────────────────────┐
│ THE WEB │
├─────────────────┬───────────────┬───────────────┤
│ HTML │ CSS │ JavaScript │
│ (Structure) │ (Presentation)│ (Behavior) │
└─────────────────┴───────────────┴───────────────┘
A Simple Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple JavaScript Example</title>
<script>
// Function to be called when the button is clicked
function showMessage() {
alert('Hello! You just clicked the button.');
}
</script>
</head>
<body>
<!-- Button that triggers the showMessage function -->
<button onclick="showMessage()">Click Me!</button>
</body>
</html>
What happens:
- The
<script>tag contains JavaScript code - The
showMessage()function displays an alert when called - The
onclickattribute on the button calls the function when clicked - This is a simple example of event-driven programming
a. JavaScript Introduction
| Aspect | Description |
|---|---|
| Type | Versatile, interpreted programming language |
| Primary Use | Adding interactivity and dynamic behavior to web pages |
| Runs On | Web browsers, servers (Node.js), desktop (Electron), mobile (React Native) |
| Created By | Brendan Eich at Netscape in 1995 |
| Role | One of the core technologies of the World Wide Web (with HTML and CSS) |
Where JavaScript Runs:
| Platform | Technology | Example |
|---|---|---|
| Browsers | Native | Chrome, Firefox, Safari |
| Servers | Node.js | Backend APIs, web servers |
| Desktop | Electron | VS Code, Slack, Discord |
| Mobile | React Native, Ionic | iOS & Android apps |
b. JavaScript Key Features
| Feature | Description |
|---|---|
| Interactivity | Creates interactive web pages that change on user actions |
| Client-Side Execution | Runs in the browser, reducing server load |
| Rich Web Applications | Supports complex apps through frameworks (React, Angular, Vue.js) for SPAs |
| Cross-Platform Compatibility | Runs in browsers, Node.js, IoT devices, and more |
| Event-Driven Programming | Responds to events like clicks, key presses, and browser actions |
| Rich API | Built-in functions for manipulating images, videos, hardware, and more |
| Dynamic Typing | Variable types are determined at runtime and can change |
| Popularity | Widely used for both front-end and back-end development |
Event-Driven Example:
// Common events
button.addEventListener('click', handleClick);
input.addEventListener('keydown', handleKeyPress);
window.addEventListener('load', initializeApp);
form.addEventListener('submit', handleSubmit);
Dynamic Typing Example:
let value = 42; // Number
value = "Hello"; // Now a String
value = true; // Now a Boolean
value = [1, 2, 3]; // Now an Array
Popular Frameworks:
| Framework | Created By | Best For |
|---|---|---|
| React | Meta (Facebook) | Component-based UIs |
| Angular | Enterprise applications | |
| Vue.js | Evan You | Progressive enhancement |
c. JavaScript Versions 1/2
| Version | Year | Key Features |
|---|---|---|
| ES1 | 1997 | First release |
| ES2 | 1998 | Minor changes |
| ES3 | 1999 | Regular expressions, do-while, switch, try/catch |
| ES4 | — | Never released |
| ES5 | 2009 | Strict mode, multiline strings, String.trim(), array methods, object methods, getters/setters, trailing commas |
| ES6 | 2015 | let and const, Map and Set, arrow functions, for/of loop, array methods, Symbol, classes, promises, modules, new number methods, spread operator |
| ES7 | 2016 | Exponential (**) operator, Array.includes() |
| ES8 | 2017 | async/await, Object.entries(), Object.values(), Object.getOwnPropertyDescriptor(), string padding |
d. JavaScript Versions 2/2
| Version | Year | Key Features |
|---|---|---|
| ES9 | 2018 | Rest object properties, shared memory, Promise.finally(), new RegExp features |
| ES10 | 2019 | String.trimStart(), String.trimEnd(), Array.flat(), revised Array.sort(), revised JSON.stringify()/toString(), Object.fromEntries() |
| ES11 | 2020 | Nullish coalescing operator (??), BigInt primitive data type |
| ES12 | 2021 | String.replaceAll(), Promise.any() |
| ES13 | 2022 | Static block inside classes, new class features, top-level await |
| ES14 | 2023 | Array.findLast() & findLastIndex(), Hashbang grammar, Symbols as WeakMap keys |
Version Timeline:
1997 ─── ES1 ── First release
1998 ─── ES2 ── Minor changes
1999 ─── ES3 ── Regular expressions
2009 ─── ES5 ── Strict mode
2015 ─── ES6 ── Modern JavaScript
2016 ─── ES7 ── Exponentiation operator
2017 ─── ES8 ── Async/await
2018 ─── ES9 ── Rest properties
2019 ─── ES10 ── Array.flat()
2020 ─── ES11 ── Nullish coalescing
2021 ─── ES12 ── replaceAll()
2022 ─── ES13 ── Top-level await
2023 ─── ES14 ── findLast()
Note: Since ES6 (2015), new versions are released annually and named by year (ES2015, ES2016, etc.). Both naming conventions are used interchangeably.
Complete Example
Here’s a complete example demonstrating JavaScript’s key features — interactivity, event handling, and dynamic content:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript Introduction — Complete Example</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background: #f8f9fa;
color: #333;
line-height: 1.6;
}
h1 { color: #007bff; border-bottom: 3px solid #007bff; padding-bottom: 10px; }
h2 { color: #28a745; border-left: 4px solid #28a745; padding-left: 15px; margin-top: 30px; }
.demo-box {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
margin: 15px 0;
}
button {
padding: 12px 24px;
background: #007bff;
color: white;
border: none;
border-radius: 8px;
font-size: 1em;
font-weight: bold;
cursor: pointer;
margin: 5px;
transition: all 0.3s;
}
button:hover {
background: #0056b3;
transform: translateY(-2px);
box-shadow: 0 4px 15px rgba(0, 123, 255, 0.3);
}
#output {
background: #e9ecef;
padding: 15px;
border-radius: 8px;
margin-top: 15px;
min-height: 50px;
font-family: 'Courier New', monospace;
border-left: 4px solid #007bff;
}
</style>
</head>
<body>
<h1>JavaScript Introduction</h1>
<div class="demo-box">
<h2>1. Interactivity</h2>
<p>Click the button to see JavaScript in action:</p>
<button onclick="showMessage()">Click Me!</button>
</div>
<div class="demo-box">
<h2>2. Dynamic Content</h2>
<p>JavaScript can change the page content dynamically:</p>
<button onclick="changeContent()">Change Content</button>
<button onclick="resetContent()">Reset</button>
<p id="dynamic-text">This text will change when you click the button.</p>
</div>
<div class="demo-box">
<h2>3. Calculations</h2>
<p>JavaScript can perform calculations:</p>
<button onclick="calculate()">Calculate 15 × 24</button>
<div id="output">Result will appear here...</div>
</div>
<div class="demo-box">
<h2>4. Date and Time</h2>
<p>JavaScript can access the current date and time:</p>
<button onclick="showDateTime()">Show Date & Time</button>
<div id="datetime-output">Click to see the current date and time</div>
</div>
<script>
// 1. Interactivity — Alert
function showMessage() {
alert('Hello! You just clicked the button.');
}
// 2. Dynamic Content — Change text
function changeContent() {
const el = document.getElementById('dynamic-text');
el.textContent = '✨ The content has been changed by JavaScript!';
el.style.color = '#28a745';
el.style.fontWeight = 'bold';
}
function resetContent() {
const el = document.getElementById('dynamic-text');
el.textContent = 'This text will change when you click the button.';
el.style.color = '#333';
el.style.fontWeight = 'normal';
}
// 3. Calculations — Multiply numbers
function calculate() {
const result = 15 * 24;
document.getElementById('output').textContent =
'15 × 24 = ' + result;
}
// 4. Date and Time — Display current date
function showDateTime() {
const now = new Date();
const options = {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
};
document.getElementById('datetime-output').textContent =
'🕐 ' + now.toLocaleDateString('en-US', options);
}
// Log to console on page load
console.log('JavaScript Introduction page loaded successfully!');
console.log('This message appears in the browser console (F12).');
</script>
</body>
</html>
How to run it:
- Save the code as
index.html - Open it in any web browser
- Click the buttons to see JavaScript in action
- Press
F12to open the console and see the log messages
Quick Reference
| Concept | Description |
|---|---|
| JavaScript | Interpreted programming language for the web |
| Core Technologies | HTML (structure), CSS (presentation), JS (behavior) |
| Creator | Brendan Eich (1995, Netscape) |
| Standard | ECMAScript (ES) |
| Latest Version | ES14 (2023) |
| Primary Use | Web interactivity |
| Runs On | Browsers, Node.js, Electron, React Native |
| Typing | Dynamic |
| Paradigm | Multi-paradigm (OOP, functional) |
Key Features Summary
| Feature | Example |
|---|---|
| Interactivity | button.addEventListener('click', handler) |
| Client-Side Execution | Runs in the browser, no server needed |
| Rich Web Applications | React, Angular, Vue.js |
| Cross-Platform | Browsers, servers, mobile, desktop, IoT |
| Event-Driven | Responds to clicks, keys, scrolls |
| Rich API | DOM, Fetch, Canvas, Web Audio |
| Dynamic Typing | let x = 5; x = "hello"; |
| Popularity | #1 most used language worldwide |
Best Practices
✅ Do This:
// Use descriptive function names
function calculateTotal() { }
// Use const by default, let when reassignment needed
const name = 'John';
let count = 0;
// Use console.log for debugging
console.log('Debug:', value);
// Comment your code
// This function calculates the total price
function getTotal() { }
❌ Don’t Do This:
// Don't use vague names
function x() { }
// Don't use var (use let/const instead)
var name = 'John';
// Don't use alert() for debugging
alert(value);
// Don't write code without comments
function a(b, c) { return b * c; }
Version Naming Convention
Since 2015, ECMAScript versions are named by year instead of number:
| Number | Year Name | Common Name |
|---|---|---|
| ES6 | ES2015 | ES6 |
| ES7 | ES2016 | ES7 |
| ES8 | ES2017 | ES8 |
| ES9 | ES2018 | ES9 |
| ES10 | ES2019 | ES10 |
| ES11 | ES2020 | ES11 |
| ES12 | ES2021 | ES12 |
| ES13 | ES2022 | ES13 |
| ES14 | ES2023 | ES14 |
Both naming conventions are used interchangeably in the developer community.
Pro Tip: JavaScript was created in just 10 days by Brendan Eich in 1995. It was originally called Mocha, then LiveScript, before being renamed to JavaScript — a marketing move to capitalize on Java’s popularity. Despite the name, JavaScript and Java are completely unrelated languages!
Stop using slow, ad-bloated tool sites! 🤮
🔎 Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)
⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free
🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!