JavaScript (Notes)
1. Introduction to JavaScript:
JavaScript is a high-level, interpreted programming language that runs in
the browser and enables interactive web pages.
JavaScript is event-driven, meaning it responds to user actions like clicks,
form submissions, etc.
2. JavaScript Basics:
Variables: JavaScript uses var, let, and const to declare variables.
o let and const are block-scoped, while var is function-scoped.
let age = 25;
const name = "John";
3. Functions:
Functions in JavaScript can be defined in several ways: function
declarations, expressions, and arrow functions.
function greet() {
console.log("Hello, World!");
}
Arrow Functions: Shorter syntax for functions.
const greet = () => console.log("Hello, World!");
4. DOM Manipulation:
The DOM (Document Object Model) represents the structure of the web
page.
JavaScript can change the content, structure, and style of HTML elements
on the page dynamically.
document.getElementById("demo").innerHTML = "Changed content";
5. Asynchronous Programming:
Callbacks: Functions passed as arguments to be executed later.
Promises: Represent values that may not yet be available.
let promise = new Promise((resolve, reject) => {
resolve("Success!");
});
Async/Await: Simplified syntax for working with asynchronous code.
async function fetchData() {
let response = await fetch('url');
let data = await response.json();
console.log(data);
}