|

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 onclick attribute on the button calls the function when clicked
  • This is a simple example of event-driven programming

a. JavaScript Introduction

AspectDescription
TypeVersatile, interpreted programming language
Primary UseAdding interactivity and dynamic behavior to web pages
Runs OnWeb browsers, servers (Node.js), desktop (Electron), mobile (React Native)
Created ByBrendan Eich at Netscape in 1995
RoleOne of the core technologies of the World Wide Web (with HTML and CSS)

Where JavaScript Runs:

PlatformTechnologyExample
BrowsersNativeChrome, Firefox, Safari
ServersNode.jsBackend APIs, web servers
DesktopElectronVS Code, Slack, Discord
MobileReact Native, IoniciOS & Android apps

b. JavaScript Key Features

FeatureDescription
InteractivityCreates interactive web pages that change on user actions
Client-Side ExecutionRuns in the browser, reducing server load
Rich Web ApplicationsSupports complex apps through frameworks (React, Angular, Vue.js) for SPAs
Cross-Platform CompatibilityRuns in browsers, Node.js, IoT devices, and more
Event-Driven ProgrammingResponds to events like clicks, key presses, and browser actions
Rich APIBuilt-in functions for manipulating images, videos, hardware, and more
Dynamic TypingVariable types are determined at runtime and can change
PopularityWidely 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:

FrameworkCreated ByBest For
ReactMeta (Facebook)Component-based UIs
AngularGoogleEnterprise applications
Vue.jsEvan YouProgressive enhancement

c. JavaScript Versions 1/2

VersionYearKey Features
ES11997First release
ES21998Minor changes
ES31999Regular expressions, do-while, switch, try/catch
ES4Never released
ES52009Strict mode, multiline strings, String.trim(), array methods, object methods, getters/setters, trailing commas
ES62015let and const, Map and Set, arrow functions, for/of loop, array methods, Symbol, classes, promises, modules, new number methods, spread operator
ES72016Exponential (**) operator, Array.includes()
ES82017async/await, Object.entries(), Object.values(), Object.getOwnPropertyDescriptor(), string padding

d. JavaScript Versions 2/2

VersionYearKey Features
ES92018Rest object properties, shared memory, Promise.finally(), new RegExp features
ES102019String.trimStart(), String.trimEnd(), Array.flat(), revised Array.sort(), revised JSON.stringify()/toString(), Object.fromEntries()
ES112020Nullish coalescing operator (??), BigInt primitive data type
ES122021String.replaceAll(), Promise.any()
ES132022Static block inside classes, new class features, top-level await
ES142023Array.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:

  1. Save the code as index.html
  2. Open it in any web browser
  3. Click the buttons to see JavaScript in action
  4. Press F12 to open the console and see the log messages

Quick Reference

ConceptDescription
JavaScriptInterpreted programming language for the web
Core TechnologiesHTML (structure), CSS (presentation), JS (behavior)
CreatorBrendan Eich (1995, Netscape)
StandardECMAScript (ES)
Latest VersionES14 (2023)
Primary UseWeb interactivity
Runs OnBrowsers, Node.js, Electron, React Native
TypingDynamic
ParadigmMulti-paradigm (OOP, functional)

Key Features Summary

FeatureExample
Interactivitybutton.addEventListener('click', handler)
Client-Side ExecutionRuns in the browser, no server needed
Rich Web ApplicationsReact, Angular, Vue.js
Cross-PlatformBrowsers, servers, mobile, desktop, IoT
Event-DrivenResponds to clicks, keys, scrolls
Rich APIDOM, Fetch, Canvas, Web Audio
Dynamic Typinglet 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:

NumberYear NameCommon Name
ES6ES2015ES6
ES7ES2016ES7
ES8ES2017ES8
ES9ES2018ES9
ES10ES2019ES10
ES11ES2020ES11
ES12ES2021ES12
ES13ES2022ES13
ES14ES2023ES14

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!