Javascript Notes - by Prakash
Javascript Notes - by Prakash
JAVASCRIPT
COMPLETE GUIDE
Overview
Introduction to JavaScript:
What is JavaScript?
Why use JavaScript?
Brief history and evolution.
Basic Syntax:
Functions:
DOM Manipulation:
Asynchronous JavaScript:
Callback functions.
Promises.
Async/await.
Error Handling:
ES6 Features:
Modules:
Browser APIs:
Local Storage.
Fetch API for making HTTP requests.
Geolocation API.
Regular Expressions:
Strict Mode:
Introduction to strict mode.
Benefits and limitations.
Basic Syntax:
Explanation: JavaScript syntax includes variables, data types, operators, and control
structures.
let x = 5;
if (x > 0) {
console.log("Positive");
} else {
console.log("Non-positive");
Functions:
Explanation: Functions are blocks of reusable code. They can take parameters and
return values.
CODE :
function greet(name) {
console.log(greet("John"));
DOM Manipulation:
document.getElementById("myButton").addEventListener("click", function() {
});
Asynchronous JavaScript:
function fetchData() {
setTimeout(() => {
}, 2000);
});
}
fetchData().then(data => {
console.log(data);
});
Error Handling:
} catch (error) {
console.error(error.message);
ES6 Features:
Explanation: ES6 introduced new features like let and const for variable declaration,
arrow functions, template literals, etc.
Example using arrow function:
CODE :
console.log(square(5)); // Output: 25
Modules:
CODE :
// main.js
Browser APIs:
CODE :
localStorage.setItem("username", "John");
Regular Expressions:
CODE :
Strict Mode:
Explanation: Strict mode enforces stricter parsing and error handling, helping to
write cleaner and more secure
x = 3.14; // Throws an error in strict mode
Explanation: Iterators are objects that provide a way to iterate over data
collections. Generators are functions that enable easy iteration with custom-
defined sequences.
Example using Iterators:
let arr = [1, 2, 3];
function* generator() {
yield 1;
yield 2;
yield 3;
Higher-order Functions:
function higherOrderFunction(callback) {
callback();
function callbackFunction() {
Promises:
setTimeout(() => {
resolve("Promise resolved");
}, 2000);
});
promise.then(result => {
});
Async/Await:
setTimeout(() => {
}, 2000);
});
fetchData();
Closures:
Explanation: Closures are functions that have access to variables from their
outer scope even after the outer function has finished executing.
Example:
function outerFunction() {
function innerFunction() {
console.log(outerVariable);
return innerFunction;
Event Loop:
console.log("Start");
setTimeout(() => {
console.log("Timeout");
}, 0);
Promise.resolve().then(() => {
console.log("Promise");
});
console.log("End");
Output:
Start
End
Promise
Timeout