JavaScript

The Programming Language of the Web

Dynamic Interactive Versatile Powerful

What is JavaScript?

JavaScript is a high-level, interpreted programming language that conforms to the ECMAScript specification. It is a language that is also characterized as dynamic, weakly typed, prototype-based and multi-paradigm.

Alongside HTML and CSS, JavaScript is one of the core technologies of the World Wide Web. JavaScript enables interactive web pages and is an essential part of web applications. The vast majority of websites use it for client-side page behavior, and all major web browsers have a dedicated JavaScript engine to execute it.

Key Features of JavaScript

Client-Side Execution

Runs directly in the browser without needing constant communication with the server

Object-Oriented

Supports object-oriented programming with prototype-based inheritance

Event-Driven

Responds to user interactions like clicks, form submissions, and keyboard events

API Integration

Can interact with browser APIs and third-party services

JavaScript Basics

JavaScript includes standard programming features like variables, data types, operators, control structures, functions, and objects. Here's a simple example:

// Variables and data types
let message = "Hello, World!"; // String
const score = 100; // Number
let isActive = true; // Boolean

// Function definition
function greet(name) {
    return `Hello, ${name}!`;
}

// Function call
const greeting = greet("Alice");
console.log(greeting); // Output: Hello, Alice!

// Conditional statement
if (score > 50) {
    console.log("You passed!");
} else {
    console.log("Try again!");
}
Variables

Use let, const, or var to store and manage data

Functions

Reusable blocks of code that perform specific tasks

Control Flow

Conditionals and loops to control program execution

DOM Manipulation

One of JavaScript's most powerful features is its ability to manipulate the Document Object Model (DOM), which represents the structure of an HTML document:

// Selecting elements
const button = document.querySelector('#myButton');
const items = document.querySelectorAll('.item');

// Adding event listeners
button.addEventListener('click', function() {
    // Modify CSS styles
    this.style.backgroundColor = 'blue';
    
    // Change text content
    this.textContent = 'Clicked!';
    
    // Add/remove classes
    this.classList.add('active');
});

// Creating new elements
const newDiv = document.createElement('div');
newDiv.textContent = 'New element';
document.body.appendChild(newDiv);
Button not clicked yet.

JavaScript Frameworks and Libraries

JavaScript has a rich ecosystem of frameworks and libraries that extend its capabilities for building complex applications:

React

A declarative, efficient, and flexible JavaScript library for building user interfaces

Angular

A platform and framework for building single-page client applications using HTML and TypeScript

Vue.js

A progressive framework for building user interfaces that is designed to be incrementally adoptable

Node.js

A JavaScript runtime built on Chrome's V8 JavaScript engine for building server-side applications

Express.js

A minimal and flexible Node.js web application framework that provides a robust set of features

jQuery

A fast, small, and feature-rich JavaScript library that simplifies HTML document traversal and manipulation

JavaScript Version History

JavaScript 1.0 (1995)

Originally developed by Brendan Eich at Netscape under the name Mocha, then LiveScript, finally JavaScript.

ECMAScript 3 (1999)

Added regular expressions, better string handling, try/catch exception handling, and more.

ECMAScript 5 (2009)

Added strict mode, JSON support, functional array methods, and property descriptors.

ECMAScript 6 (2015)

Major update with classes, modules, arrow functions, promises, and many new syntax features.

ECMAScript 2016-2022

Annual releases with incremental improvements including async/await, optional chaining, and nullish coalescing.

Getting Started with JavaScript

JavaScript can be added to HTML documents in several ways:

<!-- Internal JavaScript -->
<script>
    console.log("Hello from internal JavaScript!");
</script>

<!-- External JavaScript -->
<script src="script.js"></script>

<!-- Inline JavaScript -->
<button onclick="alert('Button clicked!')">Click Me</button>
JavaScript Documentation