Javascript
---
## π¨ What is JavaScript?
**JavaScript** is a high-level, interpreted **programming language** primarily used to **add interactivity to websites**.
It runs directly in the **browser** (like Chrome, Firefox, etc.) and is also used on the **server-side** with environments like **Node.js**.
---
## π§ Key Features:
| Feature | Description |
| ---------------- | -------------------------------------------------------------------------- |
| **Client-side** | Runs in the browser (e.g., for animations, forms, events) |
| **Server-side** | Can run backend logic with Node.js |
| **Dynamic** | Can update the DOM (HTML) and CSS live, without reloading the page |
| **Event-driven** | Reacts to user actions like clicks, scrolls, typing |
| **Asynchronous** | Uses `callbacks`, `promises`, and `async/await` to handle background tasks |
---
## π Where is JavaScript Used?
* Making websites interactive (buttons, sliders, forms)
* Handling browser events (click, hover, drag)
* Sending/receiving data via APIs (AJAX, Fetch)
* Building full-stack web apps (Node.js, Express)
* Mobile apps (React Native)
* Desktop apps (Electron)
---
## βοΈ Basic JavaScript Example:
```html
<!DOCTYPE html>
<html>
<body>
<h1 id="title">Hello!</h1>
<button onclick="changeText()">Click Me</button>
<script>
function changeText() {
document.getElementById("title").innerText = "You clicked the button!";
}
</script>
</body>
</html>
```
πΉ Clicking the button **changes the text** β all done with JavaScript!
---
## π¦ JavaScript on the Server (Node.js):
```js
const http = require('http');
http.createServer((req, res) => {
res.end('Hello from Node.js server!');
}).listen(3000);
```
You can now write **backends**, connect to databases, handle files, and build APIs β all with JavaScript.
---
## π§© Popular Tools/Libraries:
| Type | Examples |
| ----------------- | -------------------------- |
| UI Libraries | React, Vue, Svelte |
| Server Frameworks | Express.js, NestJS |
| Testing Tools | Jest, Mocha, Cypress |
| Package Manager | npm (Node Package Manager) |
---
## π§ Why Learn JavaScript?
* Itβs the **language of the web**
* Every browser supports it
* Full-stack development with a **single language**
* Huge community and job opportunities