JavaScript ekta high-level, interpreted, single-threaded, dynamically typed programming language.
-
Basic Syntax & Variables
How to write statements, comments, and declare variables withvar,let, andconst. -
Data Types
Primitive types (number, string, boolean, null, undefined, symbol, bigint) and reference types (objects, arrays, functions). -
Operators
Arithmetic (+ - * / %), comparison (==,===,>,<), logical (&&,||,!), and the ternary operator. -
Conditionals
Decision making usingif,else if,else, andswitchto run different code based on conditions. -
Loops
Repeating code withfor,while,do...while, and controlling flow usingbreakandcontinue. -
Functions
Reusable blocks of code: function declarations, function expressions, arrow functions, parameters, and return values. -
Arrays
Ordered lists of values, indexing, looping, and useful methods likepush,pop,map,filter,reduce. -
Objects
Key–value structures to group related data and behavior, object methods, and destructuring. -
Scope, Hoisting, var / let / const
How variable visibility works (global, function, block scope), what hoisting is, and howvar,let,constdiffer. -
Error Handling
Handling runtime errors withtry,catch,finally, and creating custom errors withthrow. -
Asynchronous Basics
Non-blocking code usingsetTimeout, callbacks, Promises, andasync/await. -
DOM Basics
Interacting with web pages: selecting elements, updating content/styles, and handling events like clicks.
- number – Any numeric value (integers or decimals), e.g.
10,3.14. - string – Text inside quotes, e.g.
"Hello",'Rahim'. - boolean – Only
trueorfalse, mainly for conditions. - null – An intentional “empty” value, meaning “nothing here”.
- undefined – A declared variable that has not been given any value yet.
- symbol – A special, unique, and immutable identifier, used in advanced cases.
- bigint – Very large integers beyond normal number range, e.g.
12345678901234567890n.
- Statements, semicolons, comments
- Variables:
var,let,const - Primitive types: number, string, boolean, null, undefined, symbol, bigint
- Reference types: objects, arrays, functions
Practice:
// 1) Create variables for a student:
const studentName = "Afjal";
let studentAge = 23;
let isPassed = true;
// 2) Log a sentence using them:
console.log(studentName + " is " + studentAge + " years old.");- Arithmetic:
+ - * / % ** - Comparison:
== === != !== > < >= <= - Logical:
&& || ! - Ternary operator
-
if / else if / else,switch
Practice:
const marks = 72;
let grade;
if (marks >= 80) {
grade = "A+";
} else if (marks >= 70) {
grade = "A";
} else if (marks >= 60) {
grade = "A-";
} else {
grade = "Below A-";
}
console.log("Grade:", grade);
// Ternary for pass/fail:
const result = marks >= 40 ? "Pass" : "Fail";
console.log("Result:", result);-
forloop -
whileloop -
do...whileloop -
break,continue
Practice:
// Print 1 to 10 but skip 5
for (let i = 1; i <= 10; i++) {
if (i === 5) continue;
console.log(i);
}- Function declaration
- Function expression
- Arrow function
- Parameters, return
- Global vs function vs block scope
Practice:
function add(a, b) {
return a + b;
}
const multiply = function (a, b) {
return a * b;
};
const square = (x) => x * x;
console.log(add(2, 3));
console.log(multiply(2, 3));
console.log(square(5));- Create & access items
-
push,pop,shift,unshift - Loop through arrays (
for,for...of) -
map,filter,reducebasic idea
Practice:
const scores = [40, 55, 70, 90];
const passed = scores.filter(score => score >= 50);
const doubled = scores.map(score => score * 2);
const total = scores.reduce((sum, score) => sum + score, 0);
console.log("Passed:", passed);
console.log("Doubled:", doubled);
console.log("Total:", total);- Create objects
- Access: dot vs bracket
- Methods (
this) - Destructuring
Practice:
const user = {
name: "Rahim",
age: 20,
isStudent: true,
greet() {
console.log("Hi, I'm " + this.name);
},
};
user.greet();
const { name, age } = user;
console.log(name, age);-
varvsletvsconstdifference - Block scope vs function scope
- Hoisting concept
Practice (just observe output):
console.log(a); // ?
var a = 5;
if (true) {
let b = 10;
}
// console.log(b); // Uncomment to see error-
setTimeout,setInterval - Promise ki
-
async/awaitbasic usage
Practice:
function wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function run() {
console.log("Start");
await wait(1000);
console.log("After 1 second");
}
run();-
try / catch / finally -
throwdiye custom error
Practice:
function divide(a, b) {
if (b === 0) {
throw new Error("Cannot divide by zero");
}
return a / b;
}
try {
console.log(divide(10, 2));
console.log(divide(10, 0));
} catch (err) {
console.log("Caught error:", err.message);
} finally {
console.log("Done");
}- Element select (
getElementById,querySelector) - Text/style change
- Event listener
Practice (HTML + JS):
<button id="btn">Click me</button>
<p id="text">Hello</p>
<script>
const btn = document.getElementById("btn");
const text = document.getElementById("text");
btn.addEventListener("click", () => {
text.textContent = "Button clicked!";
});
</script>