⚡ JavaScript Quick Revision Notes
1. Variables
let x = 10; // block-scoped, re-assignable
const y = 20; // block-scoped, NOT re-assignable
var z = 30; // function-scoped (avoid using)
👉 Prefer
const&
letinstead of
var
.
2. Data Types
string
● Primitive: number
, boolean
, null
, undefined
, symbol
, bigint
,
object
● Reference: array
, function
,
typeof 42; // "number"
typeof "Hi"; // "string"
typeof null; // "object" (quirk!)
3. Functions
// Function declaration
function add(a, b) { return a + b; }
// Function expression
const multiply = function(a, b) { return a * b; };
// Arrow function
const square = n => n * n;
4. Template Literals
onst name = "Aman";
c
[Link](`Hello, ${name}!`);
👉 Easier string concatenation.
5. Objects & Arrays
onst person = { name: "Aman", age: 21 };
c
[Link]([Link]);
onst arr = [1, 2, 3];
c
[Link](4); // add
[Link](); // remove
6. Destructuring
onst { name, age } = person;
c
const [first, second] = arr;
7. Spread & Rest
onst nums = [1, 2, 3];
c
const newNums = [...nums, 4]; // spread
function sum(...args) {
return [Link]((a, b) => a + b, 0);
}
8. Default Parameters
function greet(name = "Guest") {
return `Hello, ${name}`;
}
9. Callbacks, Promises, Async
// Callback
setTimeout(() => [Link]("Done!"), 1000);
// Promise
fetch("/data")
.then(res => [Link]())
.then(data => [Link](data));
// Async/Await
async function getData() {
const res = await fetch("/data");
const data = await [Link]();
[Link](data);
}
10. Classes
class Animal {
constructor(name) { [Link] = name; }
speak() { [Link](`${[Link]} makes a sound`); }
}
class Dog extends Animal {
speak() { [Link](`${[Link]} barks`); }
}
11. Modules
// file: [Link]
export const add = (a, b) => a + b;
// file: [Link]
import { add } from "./[Link]";
12. Map, Filter, Reduce
[1, 2, 3].map(x => x * 2); // [2,4,6]
[1, 2, 3].filter(x => x > 1); // [2,3]
[1, 2, 3].reduce((a, b) => a + b); // 6
13. Truthy & Falsy
false
● Falsy: 0
, ""
, null
, undefined
, NaN
,
● Everything else is truthy.
if ("") [Link]("Yes"); // won't run
14. Equality
== "0"; // true (loose equality)
0
0 === "0"; // false (strict equality)
👉 Always prefer
===
.
15. Set & Map
onst s = new Set([1, 2, 2]); // {1,2}
c
const m = new Map();
[Link]("a", 1);
[Link]([Link]("a")); // 1
16. Error Handling
try {
throw new Error("Something went wrong");
} catch (err) {
[Link]([Link]);
}
17. DOM Basics
[Link]("title").textContent = "Hello!";
d
[Link]("p").forEach(p => [Link] = "blue");
18. Events
[Link]("btn").addEventListener("click", () => {
alert("Button clicked!");
});
19. Local Storage
l[Link]("theme", "dark");
const theme = [Link]("theme");
20. Important Best Practices
const
● Use /
l
et→ avoid
var
.
===over
● Always prefer ==
.
● Writesmall, reusable functions.
● Useasync/awaitinstead of nested promises.
● Keep code DRY (Don’t Repeat Yourself).