JavaScript چیٹ شیٹ
جدید JavaScript کا ایک قابلِ تلاش، قابلِ پرنٹ حوالہ — سنٹیکس، arrays، strings، objects، async/await، DOM اور ES2022+ خصوصیات۔ مفت۔
Variables & types
10let x = 1;
const PI = 3.14;
typeof value
Number('42')
String(42)
parseInt('42px', 10)
Boolean(0)
value ?? 'default'
a?.b?.c
Array.isArray(x)
Functions
9function add(a, b) { return a + b; }
const add = (a, b) => a + b;
const f = (a = 1) => a;
function f(...args) {}
f(...arr)
const { a, b } = obj;
const [x, y] = arr;
(function(){})()
fn.bind(this)
Strings
10`Hello ${name}`
str.length
str.includes('a')
str.slice(0, 3)
str.replace(/a/g, 'b')
str.split(',')
str.trim()
str.toUpperCase()
str.padStart(3, '0')
str.at(-1)
Arrays
11arr.map(x => x * 2)
arr.filter(x => x > 0)
arr.reduce((a, b) => a + b, 0)
arr.find(x => x.id === 1)
arr.some(x => x > 0)
arr.every(x => x > 0)
arr.includes(3)
arr.sort((a, b) => a - b)
[...new Set(arr)]
arr.flat(Infinity)
arr.at(-1)
Objects
9Object.keys(obj)
Object.values(obj)
Object.entries(obj)
{ ...a, ...b }
Object.assign({}, a, b)
Object.freeze(obj)
{ [key]: value }
obj.hasOwnProperty('x')
structuredClone(obj)
Async & promises
9async function f() {}
await fetch(url)
Promise.all([p1, p2])
Promise.allSettled([p1, p2])
Promise.race([p1, p2])
new Promise((res, rej) => {})
try { await f(); } catch (e) {}
setTimeout(fn, 1000)
queueMicrotask(fn)
Control flow
9if (a) {} else if (b) {} else {}
a ? b : c
switch (x) { case 1: break; }
for (const x of arr) {}
for (const k in obj) {}
while (cond) {}
arr.forEach((x, i) => {})
break / continue
label: for (...) { break label; }
DOM & events
10document.querySelector('.x')
document.querySelectorAll('.x')
el.addEventListener('click', fn)
el.classList.toggle('active')
el.dataset.id
el.textContent = 'hi'
el.setAttribute('aria-hidden', true)
e.preventDefault()
el.closest('.parent')
document.createElement('div')
Classes & modules
9class A extends B {}
constructor() { super(); }
#private = 1;
static create() {}
get value() {}
export default fn;
export { a, b };
import x, { y } from './m.js'
const m = await import('./m.js')
کوئی اندراج “:q” سے میل نہیں کھاتا۔
JavaScript چیٹ شیٹ کے بارے میں
یہ JavaScript cheat sheet جدید زبان کے لیے ایک تلاش کے قابل، ایک-صفحہ حوالہ ہے: متغیرات اور اقسام، فنکشنز، strings، arrays، objects، async اور promises، control flow، DOM اور events، اور classes اور modules۔ ہر اندراج ایک حقیقی کوڈ اسنپٹ کو یہ بتانے والی ایک لائن کی وضاحت کے ساتھ جوڑتی ہے کہ یہ کیا کرتا ہے۔
یہ آج واقعی استعمال ہونے والی JavaScript کے لیے لکھا گیا ہے — let اور const، arrow functions، destructuring، spread، optional chaining، template literals، async/await اور ES modules — اس لیے یہ کسی دوسری زبان سے واپس آنے پر ایک تیز یاد دہانی کے طور پر بھی کام کرتا ہے۔
پوری شیٹ کلائنٹ-سائیڈ لوڈ ہوتی ہے اور مفت ہے۔ سرچ باکس سے اسے لائیو فلٹر کریں، sticky table of contents سے سیکشنز کے درمیان جائیں، کاپی کرنے کے لیے کسی بھی اسنپٹ پر کلک کریں، اور اپنی میز کے پاس ایک JavaScript حوالے کے لیے صفحہ پرنٹ کریں۔
JavaScript چیٹ شیٹ استعمال کرنے کا طریقہ
- شیٹ کھولیں اور سیکشن لسٹ کا جائزہ لیں — Variables & types سے DOM & events سے ہوتے ہوئے Classes & modules تک۔
- ہر لائن کو لائیو فلٹر کرنے کے لیے سرچ باکس میں ٹائپ کریں؛ میچ کاؤنٹر دکھاتا ہے کہ کتنے اسنپٹس فٹ ہوتے ہیں۔
- کسی سیکشن جیسے Async & promises پر براہ راست جانے کے لیے sticky table of contents استعمال کریں۔
- کوڈ کو اپنے کلپ بورڈ پر کاپی کرنے کے لیے کسی اسنپٹ، یا اس کے کاپی آئیکن پر کلک کریں۔
- پورے حوالے کی صاف، کاغذ کے لیے موزوں کاپی کے لیے Print پر کلک کریں۔