JavaScript Notes
🔹 1. What is JavaScript?
JavaScript is a high-level, interpreted, dynamic programming
language.
Used to add interactivity to websites.
Runs in the browser (frontend) and on the server with [Link]
(backend).
Follows the ECMAScript (ES) standards.
🔹 2. JavaScript Data Types
Type Example
String "Hello"
Number 123, 3.14
Boolean true, false
Null null
Undefin
undefined
ed
{ name:
Object
"Asheesh" }
Array [1, 2, 3]
Symbol Symbol('id')
BigInt 123n
🔹 3. Variables
js
CopyEdit
var x = 10; // Function-scoped
let y = 20; // Block-scoped (Recommended)
const z = 30; // Block-scoped, cannot be reassigned
🔹 4. Operators
Arithmetic: +, -, *, /, %, **
Assignment: =, +=, -=, etc.
Comparison: ==, ===, !=, !==, <, >, etc.
Logical: &&, ||, !
Ternary: condition ? trueValue : falseValue
🔹 5. Control Statements
js
CopyEdit
if (a > b) {
[Link]("A is greater");
} else if (a === b) {
[Link]("Equal");
} else {
[Link]("B is greater");
Switch:
js
CopyEdit
switch (fruit) {
case "apple": break;
case "banana": break;
default: break;
}
🔹 6. Loops
js
CopyEdit
for (let i = 0; i < 5; i++) { }
while (condition) { }
do { } while (condition);
Array Looping:
js
CopyEdit
[Link](item => [Link](item));
[Link](item => item * 2);
🔹 7. Functions
js
CopyEdit
function add(a, b) {
return a + b;
const add = (a, b) => a + b; // Arrow function
🔹 8. Objects
js
CopyEdit
const person = {
name: "Asheesh",
age: 23,
greet() {
[Link]("Hello");
},
};
[Link]([Link]);
🔹 9. Arrays
js
CopyEdit
const fruits = ["apple", "banana"];
[Link]("mango");
[Link]();
[Link]("banana"); // true
[Link];
🔹 10. ES6+ Features
Feature Example
let, const Block-scoped variables
const sum = (a, b) => a +
Arrow Functions
b;
Template Literals Hello, ${name}
Destructuring const { name } = obj;
Spread/Rest ...arr, ...args
function greet(name =
Default Params
"Guest")
Feature Example
Promises &
For async operations
async/await
🔹 11. DOM Manipulation
js
CopyEdit
[Link]("id");
[Link](".class");
[Link] = "Text";
[Link] = "blue";
🔹 12. Events
js
CopyEdit
[Link]("click", () => {
alert("Clicked");
});
🔹 13. Hoisting
Variable and function declarations are moved to the top of their scope.
var is hoisted (initialized as undefined), but let and const are not.
🔹 14. Closures
A function that remembers its outer scope even after the outer function
has finished executing.
js
CopyEdit
function outer() {
let count = 0;
return function inner() {
count++;
[Link](count);
};
const counter = outer();
counter(); // 1
counter(); // 2
🔹 15. Callback, Promise, Async/Await
Callback:
js
CopyEdit
function greet(name, cb) {
cb(`Hello, ${name}`);
Promise:
js
CopyEdit
const promise = new Promise((resolve, reject) => {
resolve("Done!");
});
Async/Await:
js
CopyEdit
async function fetchData() {
const res = await fetch("url");
const data = await [Link]();
🔹 16. Error Handling
js
CopyEdit
try {
// risky code
} catch (error) {
[Link](error);
} finally {
// always runs
🔹 17. JSON
js
CopyEdit
const obj = { name: "Ash" };
const str = [Link](obj);
const parsed = [Link](str);
Let me know if you want practice questions, cheat sheets, or deep-dives
into:
DOM
Event bubbling
OOP in JS
Design patterns
DSA in JavaScript
or anything else!
Ask ChatGPT
Tools