0% found this document useful (0 votes)
5 views4 pages

JavaScript Cheatsheet

The document provides an overview of fundamental programming concepts including variables, data types, operators, conditions, loops, functions, arrays, objects, the 'this' keyword, strings and numbers, date and regular expressions, sets and maps, JSON, and debugging. Each section includes definitions and examples to illustrate the concepts. It serves as a concise reference for basic programming principles.

Uploaded by

Maaz Hasnain
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

JavaScript Cheatsheet

The document provides an overview of fundamental programming concepts including variables, data types, operators, conditions, loops, functions, arrays, objects, the 'this' keyword, strings and numbers, date and regular expressions, sets and maps, JSON, and debugging. Each section includes definitions and examples to illustrate the concepts. It serves as a concise reference for basic programming principles.

Uploaded by

Maaz Hasnain
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Variables

let x = 10; // changeable value store karte hain


const y = 20; // fixed value store karte hain

Definition: Variable ek container hai jisme data store hota hai.

2. Data Types

Primitive → immutable values: Number, String, Boolean, Null, Undefined, Symbol, BigInt
Reference → mutable values: Object, Array, Function, Date, RegExp, Map, Set

let str = "Hello"; // text


let num = 10; // number
let bool = true; // true/false
let arr = [1,2,3]; // list of items
let obj = {name:"Maaz"};// key-value storage
let fun = () => {}; // reusable code
let nothing = null; // intentional empty
let undef; // not assigned yet

Definition: Data type batata hai value ka nature (text, number, object, etc.)

3. Operators

 Arithmetic: + - * / % ** → numbers ke saath calculations

 Assignment: = += -= *= /= → variable me value assign karna

 Comparison: == === != !== > < >= <= → values compare karna

 Logical: && || ! → true/false logic

 Ternary: let res = age > 18 ? "Adult" : "Minor"; → short if-else

Definition: Operator data ya values pe kaam karte hain, calculations ya comparisons ke liye

4. Conditions

if(x > 10) { }


else if(x === 10) { }
else { }
switch(day){ case 1: break; default: break; }

Definition: Conditional statements program ko decide karne me help karte hain ke kaunsa block
execute hoga

5. Loops

for(let i=0;i<5;i++){}
while(cond){}
do{}while(cond){}

Definition: Loops kaam ko repeatedly execute karte hain jab tak condition true hai

6. Functions

function add(a,b){ return a+b; }


const add2 = (a,b) => a+b;

Definition: Function reusable code block hai jo input leta hai aur output deta hai

7. Arrays

[Link](4); [Link](); [Link](); [Link](0);


[Link](x=>[Link](x));
let newArr = [Link](x=>x*2);
let filtered = [Link](x=>x>2);
[Link](2); [Link](2);
[Link]((a,b)=>a-b);

Definition: Array ordered list hai values ki, index ke through access hoti hain

8. Objects

let user = {name:"Maaz", age:20};


[Link]; user["age"];
[Link]="NY";
for(let key in user){ [Link](key,user[key]); }
Definition: Object key-value pairs ka collection hai, named data store karte hain

9. this Keyword

let obj = {name:"Maaz", greet:function(){[Link]([Link]);} };


[Link](); // this = obj

Definition: this reference karta hai current object ko jisme code execute ho raha hai

10. Strings & Numbers

[Link]; [Link](); [Link]("Hello");


[Link](4.7); [Link](4.1); [Link](4.5); [Link]();

Definition: Strings = text ke liye methods; Numbers = math calculations ke liye

11. Date & RegExp

let d = new Date();


[Link](); [Link](); [Link]();
let pattern = /abc/;

Definition: Date = time & date handle karte hain; RegExp = string patterns match karne ke liye

12. Sets & Maps

let s = new Set([1,2,2]); [Link](3); [Link](2);


let m = new Map(); [Link]("a",1); [Link]("a");

Definition: Set = unique values store karta hai; Map = key-value pairs, any type key allowed

13. JSON

let obj = {name:"Maaz"};


let str = [Link](obj);
let newObj = [Link](str);

Definition: JSON = data ko string me convert karke server ya file me store/transfer karne ke liye
14. Debugging

[Link](x); [Link]("Error"); [Link](arr); debugger;

Definition: Debugging tools help karte hain errors find karne aur code test karne me

You might also like