

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


JavaScript in a Nutshell
What is JavaScript?
· A high-level, interpreted programming language · Mainly used for web development (front-end & back-end) · Runs in browsers and on servers (Node.js) · Adds interactivity to websites
Core Concepts
let name = "John"; // String const age = 25; // Number (constant) var isStudent = true; // Boolean let scores = [95, 88, 72]; // Array let person = { // Object firstName: "Jane", lastName: "Doe" }; // Arithmetic let sum = 5 + 3; // String concatenation let greeting = "Hello " + name; // Comparison let isAdult = age >= 18; function add(a, b) { return a + b; } // Arrow function (modern) const multiply = (x, y) => x * y; // If-else if (age >= 18) { console.log("Adult"); } else { console.log("Minor"); } // Loops for (let i = 0; i < 5; i++) { console.log(i); ## ``` 5. DOM Manipulation (Browser) ```javascript // Select element const button = document.getElementById("myButton"); // Change content button.textContent = "Click me!"; // Add event listener button.addEventListener("click", function() { alert("Button clicked!"); }); Key Features
· Event-driven: Responds to user actions · Asynchronous: Can handle multiple operations without blocking · Object-oriented: Uses objects and classes · Dynamic typing: Variable types determined at runtime
Common Use Cases
Modern JavaScript (ES6+)
// Template literals let message = `Hello ${name}, you are ${age} years old`; // Destructuring let [first, second] = scores; let { firstName, lastName } = person; // Promises & Async/Await async function fetchData() { let response = await fetch("url"); let data = await response.json(); return data; } Quick Tips
· Use console.log() for debugging · Modern code uses let and const instead of var · JavaScript is case-sensitive · Semicolons are optional but recommended
Learning Path