Below is a comprehensive JavaScript technical revision guide covering core concepts, control flow, data structures, functions, ES6+, async programming, common algorithms, and interview-style logic problems — with clear explanations and code snippets.
I’ve structured this like a mini handbook so you can revise section by section.
1. Variables and Data Types
var, let, const
var x = 10; // function-scoped
let y = 20; // block-scoped
const z = 30; // block-scoped, cannot be reassigned
Scope Example
function testScope() {
if (true) {
var a = 1;
let b = 2;
}
console.log(a); // 1
// console.log(b); // ReferenceError
}
Primitive Types
- string
- number
- boolean
- undefined
- null
- bigint
- symbol
let name = "John";
let age = 30;
let isActive = true;
let nothing = null;
let notDefined;
2. Operators
Arithmetic
let sum = 5 + 3;
let difference = 5 - 3;
let product = 5 * 3;
let division = 5 / 3;
let remainder = 5 % 3;
let power = 2 ** 3;
Comparison
5 == "5"; // true (loose)
5 === "5"; // false (strict)
5 !== 6; // true
Logical
true && false;
true || false;
!true;
3. Conditional Statements
if / else
let score = 75;
if (score >= 90) {
console.log("A");
} else if (score >= 70) {
console.log("B");
} else {
console.log("C");
}
Ternary Operator
let result = score >= 50 ? "Pass" : "Fail";
Switch
let day = 2;
switch(day) {
case 1:
console.log("Monday");
break;
case 2:
console.log("Tuesday");
break;
default:
console.log("Other");
}
4. Loops
for Loop
for (let i = 0; i < 5; i++) {
console.log(i);
}
while Loop
let i = 0;
while (i < 5) {
console.log(i);
i++;
}
do…while
let i = 0;
do {
console.log(i);
i++;
} while (i < 5);
for…of (arrays)
let arr = [1, 2, 3];
for (let value of arr) {
console.log(value);
}
for…in (objects)
let person = { name: "John", age: 30 };
for (let key in person) {
console.log(key, person[key]);
}
5. Functions
Function Declaration
function greet(name) {
return "Hello " + name;
}
Function Expression
const greet = function(name) {
return "Hello " + name;
};
Arrow Functions
const greet = (name) => {
return "Hello " + name;
};
// Short form
const greet = name => "Hello " + name;
Default Parameters
function greet(name = "Guest") {
return `Hello ${name}`;
}
Rest Parameters
function sum(...numbers) {
return numbers.reduce((total, num) => total + num, 0);
}
6. Arrays
Creating Arrays
let numbers = [1, 2, 3];
let empty = new Array();
Common Methods
push / pop
numbers.push(4);
numbers.pop();
shift / unshift
numbers.unshift(0);
numbers.shift();
map()
let doubled = numbers.map(n => n * 2);
filter()
let evens = numbers.filter(n => n % 2 === 0);
reduce()
let total = numbers.reduce((acc, curr) => acc + curr, 0);
find()
let found = numbers.find(n => n > 2);
some / every
numbers.some(n => n > 2);
numbers.every(n => n > 0);
7. Objects
Creating Objects
let person = {
name: "John",
age: 30,
greet() {
return `Hi, I'm ${this.name}`;
}
};
Accessing Properties
person.name;
person["age"];
Destructuring
let { name, age } = person;
Spread Operator
let newPerson = { ...person, age: 31 };
8. Classes
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
greet() {
return `Hello, I'm ${this.name}`;
}
}
const p1 = new Person("John", 30);
Inheritance
class Student extends Person {
constructor(name, age, course) {
super(name, age);
this.course = course;
}
}
9. Closures
function outer() {
let count = 0;
return function inner() {
count++;
return count;
};
}
const counter = outer();
console.log(counter()); // 1
console.log(counter()); // 2
10. Higher-Order Functions
function operate(a, b, operation) {
return operation(a, b);
}
function add(x, y) {
return x + y;
}
operate(5, 3, add);
11. Promises
let promise = new Promise((resolve, reject) => {
let success = true;
if (success) {
resolve("Success!");
} else {
reject("Error!");
}
});
Using .then()
promise
.then(result => console.log(result))
.catch(error => console.error(error));
12. Async / Await
async function fetchData() {
try {
let response = await fetch("https://api.example.com/data");
let data = await response.json();
console.log(data);
} catch (error) {
console.error(error);
}
}
13. Error Handling
try {
throw new Error("Something went wrong");
} catch (error) {
console.error(error.message);
} finally {
console.log("Cleanup");
}
14. Common Algorithm Questions
Reverse a String
function reverseString(str) {
return str.split("").reverse().join("");
}
Check Palindrome
function isPalindrome(str) {
let reversed = str.split("").reverse().join("");
return str === reversed;
}
Find Maximum in Array
function findMax(arr) {
return Math.max(...arr);
}
Remove Duplicates
function removeDuplicates(arr) {
return [...new Set(arr)];
}
FizzBuzz
for (let i = 1; i <= 100; i++) {
if (i % 3 === 0 && i % 5 === 0) {
console.log("FizzBuzz");
} else if (i % 3 === 0) {
console.log("Fizz");
} else if (i % 5 === 0) {
console.log("Buzz");
} else {
console.log(i);
}
}
Factorial
function factorial(n) {
if (n === 0) return 1;
return n * factorial(n - 1);
}
Fibonacci
function fibonacci(n) {
if (n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}
15. Sorting
let numbers = [5, 3, 8, 1];
numbers.sort((a, b) => a - b); // ascending
numbers.sort((a, b) => b - a); // descending
16. Deep vs Shallow Copy
let obj = { a: 1, b: { c: 2 } };
let shallowCopy = { ...obj };
let deepCopy = JSON.parse(JSON.stringify(obj));
17. Event Loop Concept (Important for Interviews)
JavaScript is single-threaded.
console.log("Start");
setTimeout(() => {
console.log("Timeout");
}, 0);
console.log("End");
Output:
Start
End
Timeout
18. Debounce Function (Common Interview Question)
function debounce(func, delay) {
let timeoutId;
return function(...args) {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
func.apply(this, args);
}, delay);
};
}
19. Throttle Function
function throttle(func, limit) {
let lastFunc;
let lastRan;
return function(...args) {
if (!lastRan) {
func.apply(this, args);
lastRan = Date.now();
} else {
clearTimeout(lastFunc);
lastFunc = setTimeout(() => {
if ((Date.now() - lastRan) >= limit) {
func.apply(this, args);
lastRan = Date.now();
}
}, limit - (Date.now() - lastRan));
}
};
}
20. Common Array Logic Problems
Count Occurrences
function countOccurrences(arr) {
return arr.reduce((acc, curr) => {
acc[curr] = (acc[curr] || 0) + 1;
return acc;
}, {});
}
Flatten Array
function flatten(arr) {
return arr.flat(Infinity);
}
Recursive version:
function flatten(arr) {
return arr.reduce((acc, curr) =>
Array.isArray(curr)
? acc.concat(flatten(curr))
: acc.concat(curr), []
);
}
21. Two Sum Problem
function twoSum(nums, target) {
let map = {};
for (let i = 0; i < nums.length; i++) {
let complement = target - nums[i];
if (map[complement] !== undefined) {
return [map[complement], i];
}
map[nums[i]] = i;
}
}
22. Memoization
function memoize(fn) {
let cache = {};
return function(...args) {
let key = JSON.stringify(args);
if (!cache[key]) {
cache[key] = fn.apply(this, args);
}
return cache[key];
};
}
23. Practical Interview Scenario Example
Filter + Sort + Transform
const users = [
{ name: "John", age: 25 },
{ name: "Alice", age: 30 },
{ name: "Bob", age: 20 }
];
const result = users
.filter(user => user.age > 21)
.sort((a, b) => a.age - b.age)
.map(user => user.name);
console.log(result);
Final Advice for Your Technical Test
- Practice writing code without autocomplete.
- Be comfortable with:
- Loops
- Array methods
- Objects
- Async/await
- Common algorithms
- Speak while coding (if live interview).
- Explain time complexity when appropriate.
- Handle edge cases (null, empty array, invalid input).