Introduction to JavaScript
## Learning Objectives
- Understand what JavaScript is and its history
- Set up a JavaScript development environment
- Write your first JavaScript program
## What is JavaScript?
JavaScript is a high-level, interpreted programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. It was created in 1995 by Brendan Eich while he was working at Netscape Communications Corporation.
## Key Characteristics
- **Multi-paradigm**: Supports object-oriented, imperative, and functional programming styles
- **Dynamic**: Loosely typed, allowing flexible variable declarations
- **Cross-platform**: Runs in web browsers, on servers (Node.js), and in mobile applications
- **Event-driven**: Excellent for handling user interactions and asynchronous operations
## JavaScript History
| Year | Version | Key Features |
|------|---------|--------------|
| 1995 | JavaScript 1.0 | First release in Netscape Navigator |
| 1997 | ECMAScript 1 | First standardized version |
| 2009 | ES5 | Strict mode, JSON support, array methods |
| 2015 | ES6 (ES2015) | Classes, arrow functions, let/const, modules |
| 2016+ | ES2016+ | Annual releases with new features |
## Setting Up Your Environment
### Option 1: Browser Console
1. Open your web browser (Chrome, Firefox, Edge, or Safari)
2. Open Developer Tools (F12 or Cmd+Option+I on Mac)
3. Navigate to the Console tab
4. Start typing JavaScript code
### Option 2: Node.js
```bash
# Install Node.js from https://nodejs.org
# Verify installation
node --version
npm --version
# Run a JavaScript file
node filename.js
```
### Option 3: VS Code
1. Download and install VS Code from
2. Install the "JavaScript (ES6) code snippets" extension
3. Create a new file with .js extension
4. Run using the integrated terminal or Debugger
## Your First Program
```javascript
console.log("Hello, World!");
```
### How It Works
1. `console.log()` is a function that outputs messages to the console
2. The string "Hello, World!" is the argument passed to the function
3. Strings in JavaScript can be enclosed in single quotes, double quotes, or backticks
## Where JavaScript Runs
### Browser
```javascript
// Interacts with the Document Object Model (DOM)
document.getElementById("myElement").textContent = "Hello!";
// Handles user events
button.addEventListener("click", function() {
alert("Button clicked!");
});
```
### Server (Node.js)
```javascript
// File system operations
const fs = require("fs");
fs.readFileSync("file.txt", "utf8");
// HTTP server
const http = require("http");
http.createServer((req, res) => {
res.writeHead(200);
res.end("Hello from server!");
});
```
## Summary
- JavaScript is a versatile, multi-paradigm programming language
- It runs in browsers, on servers, and in various runtime environments
- Setting up a development environment is quick and easy
- JavaScript code can be written directly in browsers or in files executed by Node.js
Comments
Comments powered by Giscus
To enable comments, add your Giscus embed code here.
Learn more about Giscus →