Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
JavaScript can run in two main environments: the browser (like Chrome, Firefox) and Node.js (on your computer/server). Same language, different capabilities!
Frontend / Client-side
Inside web browsers (Chrome, Firefox, Safari, Edge)
Make websites interactive - handle clicks, forms, animations
Backend / Server-side
On servers, your computer, IoT devices (outside browser)
Build servers, APIs, tools, scripts - backend applications
// ✅ Works in BROWSER only
// Access HTML elements
const button = document.getElementById('myButton');
button.addEventListener('click', () => {
alert('Button clicked!');
});
// Change page styles
document.body.style.backgroundColor = 'lightblue';
// Get user location
navigator.geolocation.getCurrentPosition((position) => {
console.log('Latitude:', position.coords.latitude);
console.log('Longitude:', position.coords.longitude);
});
// Store data in browser
localStorage.setItem('username', 'John');
const username = localStorage.getItem('username');
// Make HTTP request to API
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data));
// ❌ This will ERROR in Node.js
// ReferenceError: document is not defined// ✅ Works in NODE.JS only
// Read a file from computer
const fs = require('fs');
const fileContent = fs.readFileSync('data.txt', 'utf8');
console.log(fileContent);
// Write to a file
fs.writeFileSync('output.txt', 'Hello from Node.js!');
// Create a simple HTTP server
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World from Node.js server!');
});
server.listen(3000, () => {
console.log('Server running on http://localhost:3000');
});
// Access system information
const os = require('os');
console.log('Platform:', os.platform());
console.log('CPU cores:', os.cpus().length);
// Run in terminal (not browser!)
// $ node server.js
// ❌ This will ERROR in Browser
// ReferenceError: require is not defined// ✅ Works in BOTH Browser and Node.js
// Variables and data structures
const numbers = [1, 2, 3, 4, 5];
const doubled = numbers.map(n => n * 2);
console.log(doubled); // [2, 4, 6, 8, 10]
// Functions
function calculateTotal(items) {
return items.reduce((sum, item) => sum + item.price, 0);
}
// Objects and classes
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
greet() {
return `Hello, I'm ${this.name}`;
}
}
// Promises and async/await
async function fetchData() {
// Works with different fetch implementations
const response = await fetch('https://api.example.com/data');
return response.json();
}
// Array methods, string operations, math
const text = 'hello world';
const uppercase = text.toUpperCase();
const randomNum = Math.random();
// JSON operations
const user = { name: 'Alice', age: 25 };
const json = JSON.stringify(user);
const parsed = JSON.parse(json);consolesetTimeoutsetIntervalPromiseJSONMathDatewindowdocumentnavigatorlocalStoragealertlocationglobalprocess__dirname__filenamerequiremoduleRuns in web browsers
Makes websites interactive
Runs on servers/computers
Builds APIs and tools
Browser has DOM, window
Node has fs, http modules
Variables, functions, classes
Work the same everywhere