[Go to site: main page, start]

0% found this document useful (0 votes)
4 views8 pages

JavaScript 1

The JavaScript Full Cheatsheet (2025 Edition) provides a comprehensive overview of JavaScript fundamentals, including variable types, data types, operators, control flow, functions, objects, arrays, and ES6+ features. It also covers DOM manipulation, event handling, JSON, promises, async/await, modules, error handling, object-oriented programming, sets, maps, and useful built-in methods. Additionally, it includes shortcuts for safe access and nullish coalescing.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

JavaScript 1

The JavaScript Full Cheatsheet (2025 Edition) provides a comprehensive overview of JavaScript fundamentals, including variable types, data types, operators, control flow, functions, objects, arrays, and ES6+ features. It also covers DOM manipulation, event handling, JSON, promises, async/await, modules, error handling, object-oriented programming, sets, maps, and useful built-in methods. Additionally, it includes shortcuts for safe access and nullish coalescing.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript Full Cheatsheet (2025 Edition)

1. Basics
1.1 Variables

// var – function-scoped, can be redeclared


var name = "Tejas";

// let – block-scoped, can be updated but not redeclared in the same scope
let age = 25;

// const – block-scoped, cannot be updated or redeclared


const country = "India";

🔹 let and const are preferred in modern JS.


🔹 const for values that don’t change.

1.2 Data Types

Primitive: string, number, boolean, null, undefined, symbol, bigint


Non-primitive: object, array, function

let str = "Hello"; // String


let num = 42; // Number
let bigIntNum = 9007199254740991n; // BigInt
let isTrue = true; // Boolean
let nothing = null; // Null
let notDefined; // Undefined
let sym = Symbol("id"); // Symbol

1.3 Type Checking

typeof "Hello" // "string"


typeof 42 // "number"
typeof null // "object" (historical quirk)
[Link]([]) // true

2. Operators
2.1 Arithmeric
+, -, *, /, %, ** // Addition, subtraction, multiplication, division, modulus,
exponent

2.2 Assignment

let x = 10;
x += 5; // 15
x -= 5; // 10
x *= 2; // 20

2.3 Comparison

5 == "5" // true (loose equality)


5 === "5" // false (strict equality)
5 != "5" // false
5 !== "5" // true

2.4 Logical

&& // AND
|| // OR
! // NOT

3. Control Flow
3.1 If / Else

if (age >= 18) {


[Link]("Adult");
} else {
[Link]("Minor");
}

3.2 Ternary

let msg = (age >= 18) ? "Adult" : "Minor";

3.3 Switch
switch(day) {
case "Monday":
[Link]("Start of week");
break;
case "Friday":
[Link]("Weekend soon!");
break;
default:
[Link]("Another day");
}

4. Loops

// For
for (let i = 0; i < 5; i++) {
[Link](i);
}

// While
let i = 0;
while (i < 5) {
[Link](i);
i++;
}

// Do...while
let j = 0;
do {
[Link](j);
j++;
} while (j < 5);

// For...of (arrays, strings)


for (let val of [10, 20, 30]) {
[Link](val);
}

// For...in (object keys)


for (let key in {a:1, b:2}) {
[Link](key);
}

5. Functions
5.1 Declaration

function greet(name) {
return `Hello ${name}`;
}

5.2 Expression

const greet = function(name) {


return `Hello ${name}`;
}

5.3 Arrow Functions

const greet = (name) => `Hello ${name}`;

5.4 Default Parameters

function multiply(a, b = 2) {
return a * b;
}

5.5 Rest Parameters

function sum(...nums) {
return [Link]((a,b) => a+b, 0);
}

6. Objects

const person = {
name: "Tejas",
age: 25,
greet() {
[Link](`Hi, I'm ${[Link]}`);
}
};
[Link]();

🔹 this refers to the object in regular methods, but behaves differently in arrow functions.

7. Arrays
let arr = [1, 2, 3];
[Link](4); // Add at end
[Link](); // Remove last
[Link](0); // Add at start
[Link](); // Remove first
[Link](2); // true
[Link](2); // 1

Common Array Methods*

[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, 0); // 6
[1, 2, 3].forEach(x => [Link](x));

ES6+ Features
Destructuring

let [a, b] = [1, 2];


let {name, age} = {name: "Tejas", age: 25};

Spread Operator

let nums = [1, 2, 3];


let copy = [...nums];
let merged = [...nums, 4, 5];

9. DOM Manipulation

[Link]("id");
[Link](".class");
[Link]("p");

let el = [Link]("#title");
[Link] = "New Title";
[Link] = "red";

10. Events
[Link]("button")
.addEventListener("click", () => {
alert("Button clicked!");
});

11. JSON

let obj = {name: "Tejas"};


let jsonStr = [Link](obj); // object → JSON string
let parsed = [Link](jsonStr); // JSON string → object

12. Promises & Async

// Promise
let promise = new Promise((resolve, reject) => {
setTimeout(() => resolve("Done!"), 1000);
});
[Link](result => [Link](result));

// Async/Await
async function fetchData() {
let data = await fetch("[Link]
let json = await [Link]();
[Link](json);
}

13. Modules

// [Link]
export const name = "Tejas";
export function greet() { [Link]("Hi"); }

// [Link]
import {name, greet} from './[Link]';

14. Error Handling

try {
throw new Error("Something went wrong");
} catch (err) {
[Link]([Link]);
} finally {
[Link]("Always runs");
}

15. OOP in JS

class Person {
constructor(name) {
[Link] = name;
}
greet() {
[Link](`Hi, I'm ${[Link]}`);
}
}

let p = new Person("Tejas");


[Link]();

16. Set & Map

let set = new Set([1, 2, 3, 3]); // Unique values


[Link](4);
[Link](2);

let map = new Map();


[Link]("name", "Tejas");
[Link]("name");

17. Useful Built-in Methods

[Link]("42"); // 42
[Link]("42.5");// 42.5
[Link](65); // "A"
"Hello".toUpperCase(); // "HELLO"
[Link](1, 5, 3); // 5
[Link](); // 0 - 1

18. Shortcuts

let val = obj && [Link]; // Safe access


let val2 = obj?.key; // Optional chaining
let val3 = obj?.key ?? "Default"; // Nullish coalescing

You might also like