
JavaScript is one of the most popular and powerful programming languages. It is mainly used to make websites interactive, dynamic, and user-friendly. With JavaScript, we can control webpage behavior—such as responding to button clicks, validating forms, updating content without reloading the page, and building full web applications. JavaScript is not limited to browsers only; it is also used for backend development (Node.js), mobile apps, desktop apps, game development & even software automation testing. This cheat sheet is designed for absolute beginners, covering all essential JavaScript concepts with simple explanations and easy-to-understand syntax.
Basic Syntax
Printing Output:
console.log("Hello JS!");
Comments:
// Single-line comment
/*
Multi-line
comment
*/
Variables (let, const, var)
Modern JavaScript → Use let and const
let age = 20; // changeable
const name = "Manan"; // NOT changeable
var oldWay = true; // older JS, avoid using
Data Types
Primitive Types:
let name = "Manan Academy"; // string
let age = 17; // number
let isHappy = true; // boolean
let x = undefined; // undefined
let y = null; // null
let bigNum = 123n; // BigInt
let symbol = Symbol(); // symbol
Operators
Arithmetic:
+, -, *, /, %, ** // (power)
Example:
5 + 2; // 7
5 % 2; // 1
Comparison:
== // equal (loose)
=== // equal (strict)
!= // not equal
> < >= <=
Logical:
&& // AND
|| // OR
! // NOT
Strings
Template Literals:
let name = "Manan";
console.log(`Hello ${name}`);
Common String Methods:
text.length
text.toUpperCase()
text.toLowerCase()
text.includes("hi")
text.replace("a", "b")
text.slice(0, 4)
Arrays
let fruits = ["apple", "banana", "mango"];
fruits[0]; // "apple"
fruits.length; // 3
Array Methods:
fruits.push("orange"); // add
fruits.pop(); // remove last
fruits.shift(); // remove first
fruits.unshift("kiwi"); // add first
fruits.indexOf("banana");
Objects
Syntax Example:
let user = {
name: "Manan",
age: 17,
isAdmin: false
};
console.log(user.name);
console.log(user["age"]);
Add new key:
user.country = "Bangladesh";
Conditionals (if / else)
let age = 17;
if (age >= 18) {
console.log("Adult");
} else {
console.log("Minor");
}
else if:
if (score > 80) {
console.log("A");
} else if (score > 60) {
console.log("B");
}
Switch Case
Example:
let day = 3;
switch (day) {
case 1: console.log("Sun"); break;
case 2: console.log("Mon"); break;
case 3: console.log("Tue"); break;
default: console.log("Unknown");
}
Loops
For Loop
Example:
for (let i = 1; i <= 5; i++) {
console.log(i);
}
While Loop
Example:
let i = 1;
while (i <= 5) {
console.log(i);
i++;
}
For-of (best for arrays)
Example:
for (let fruit of fruits) {
console.log(fruit);
}
For-in (objects)
Example:
for (let key in user) {
console.log(key, user[key]);
}
Functions
Function Declaration Example:
function greet() {
console.log("Hello!");
}
Function with parameter:
function add(a, b) {
return a + b;
}
Arrow Function Syntax (modern JS):
const sayHi = () => console.log("Hi!");
DOM Manipulation
Select elements:
document.getElementById("title");
document.querySelector(".class");
document.querySelectorAll("p");
Change content:
document.getElementById("title").textContent = "New Title";
Change style:
document.getElementById("box").style.color = "red";
Add event:
button.addEventListener("click", () => {
alert("Button clicked!");
});
JSON
Example:
let jsonData = '{"name": "Manan", "age": 17}';
let obj = JSON.parse(jsonData); // JSON → JS object
let str = JSON.stringify(obj); // object → JSON
Async JavaScript
setTimeout Example:
setTimeout(() => {
console.log("Waited 2 seconds");
}, 2000);
Fetch API (GET request) Example:
fetch("https://api.example.com")
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.log(err));
Classes (OOP Basics)
Example:
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
greet() {
console.log(`Hi, I am ${this.name}`);
}
}
let p = new Person("Manan", 17);
p.greet();
Useful Built-in Methods
// Numbers
Number.parseInt("20");
Number.parseFloat("20.5");
//Math
Math.random()
Math.round()
Math.floor()
Math.ceil()
Math.max()
Math.min()