Introduction to JavaScript
What is JavaScript?
Section titled “What is JavaScript?”JavaScript is a programming language primarily used to make web pages dynamic and interactive.
Unlike HTML (content structure) and CSS (styling and layout), JavaScript handles the logic and behavior of a page.
It can run:
- In the browser (Chrome, Firefox, Safari, Edge) to manipulate a web page.
- Outside the browser with Node.js to build servers, scripts, or desktop applications.
A brief history
Section titled “A brief history”- 1995: Created by Brendan Eich at Netscape in just 10 days.
- Initially called Mocha, then LiveScript, and finally JavaScript (to capitalize on Java’s popularity at the time).
- Today, it is standardized by ECMA International under the official name ECMAScript (ES).
- The most widely used version today is ES6+ (ECMAScript 2015 and later).
Main roles
Section titled “Main roles”- Manipulating the DOM (HTML page content).
- Responding to events (clicks, keyboard input, etc.).
- Communicating with a server via APIs (AJAX, fetch, WebSockets).
- Creating animations and visual effects.
- Building server-side applications (e.g., with Node.js).
- Developing mobile and desktop apps (e.g., with React Native, Electron).
Simple example
Section titled “Simple example”<!DOCTYPE html><html> <body> <h1 id="title">Bonjour</h1> <button onclick="changeText()">Click me</button>
<script> function changeText() { document.getElementById("title").innerText = "Hello, JavaScript!"; } </script> </body></html>
Summary
Section titled “Summary”- JavaScript complements HTML + CSS to create rich web experiences.
- It is a universal language today, used for both front-end and back-end development.
- It is used for everything: websites, mobile apps, servers, games, and more.