ข้อมูลอ้างอิงที่ค้นหาและพิมพ์ได้ของ JavaScript สมัยใหม่ — ไวยากรณ์ อาร์เรย์ สตริง ออบเจกต์ async/await DOM และฟีเจอร์ ES2022+ ฟรี

Variables & types

10
let x = 1;
Block-scoped, reassignable variable
const PI = 3.14;
Block-scoped constant binding
typeof value
Returns the type as a string
Number('42')
Convert a string to a number
String(42)
Convert a value to a string
parseInt('42px', 10)
Parse a leading integer (base 10)
Boolean(0)
Coerce a value to true/false
value ?? 'default'
Nullish coalescing (null/undefined only)
a?.b?.c
Optional chaining, short-circuits on null
Array.isArray(x)
Check whether a value is an array

Functions

9
function add(a, b) { return a + b; }
Named function declaration
const add = (a, b) => a + b;
Arrow function with implicit return
const f = (a = 1) => a;
Default parameter value
function f(...args) {}
Rest parameters collect into an array
f(...arr)
Spread an array into arguments
const { a, b } = obj;
Object destructuring
const [x, y] = arr;
Array destructuring
(function(){})()
Immediately-invoked function (IIFE)
fn.bind(this)
Bind a fixed this context

Strings

10
`Hello ${name}`
Template literal interpolation
str.length
Number of characters
str.includes('a')
Check if a substring exists
str.slice(0, 3)
Extract part of a string
str.replace(/a/g, 'b')
Replace matches (regex)
str.split(',')
Split into an array
str.trim()
Remove surrounding whitespace
str.toUpperCase()
Convert to upper case
str.padStart(3, '0')
Pad the start to a length
str.at(-1)
Character at index (supports negatives)

Arrays

11
arr.map(x => x * 2)
Transform each element
arr.filter(x => x > 0)
Keep matching elements
arr.reduce((a, b) => a + b, 0)
Reduce to a single value
arr.find(x => x.id === 1)
First matching element
arr.some(x => x > 0)
True if any element matches
arr.every(x => x > 0)
True if all elements match
arr.includes(3)
Check for a value
arr.sort((a, b) => a - b)
Numeric ascending sort
[...new Set(arr)]
Remove duplicate values
arr.flat(Infinity)
Fully flatten nested arrays
arr.at(-1)
Last element (negative index)

Objects

9
Object.keys(obj)
Array of own enumerable keys
Object.values(obj)
Array of own values
Object.entries(obj)
Array of [key, value] pairs
{ ...a, ...b }
Merge objects (spread)
Object.assign({}, a, b)
Copy/merge into a target
Object.freeze(obj)
Make an object immutable
{ [key]: value }
Computed property name
obj.hasOwnProperty('x')
Check for an own property
structuredClone(obj)
Deep clone an object

Async & promises

9
async function f() {}
Declare an async function
await fetch(url)
Pause until a promise resolves
Promise.all([p1, p2])
Wait for all to resolve
Promise.allSettled([p1, p2])
Wait for all to settle
Promise.race([p1, p2])
Resolve with the first to settle
new Promise((res, rej) => {})
Create a promise manually
try { await f(); } catch (e) {}
Handle async errors
setTimeout(fn, 1000)
Run after a delay (ms)
queueMicrotask(fn)
Schedule a microtask

Control flow

9
if (a) {} else if (b) {} else {}
Conditional branches
a ? b : c
Ternary expression
switch (x) { case 1: break; }
Multi-way branch
for (const x of arr) {}
Iterate values (iterables)
for (const k in obj) {}
Iterate object keys
while (cond) {}
Loop while a condition holds
arr.forEach((x, i) => {})
Run a callback per element
break / continue
Exit or skip a loop iteration
label: for (...) { break label; }
Break out of nested loops

DOM & events

10
document.querySelector('.x')
First matching element
document.querySelectorAll('.x')
All matching elements (NodeList)
el.addEventListener('click', fn)
Attach an event listener
el.classList.toggle('active')
Toggle a CSS class
el.dataset.id
Read a data-id attribute
el.textContent = 'hi'
Set text safely (no HTML)
el.setAttribute('aria-hidden', true)
Set an attribute
e.preventDefault()
Cancel the default action
el.closest('.parent')
Nearest matching ancestor
document.createElement('div')
Create a new element

Classes & modules

9
class A extends B {}
Class with inheritance
constructor() { super(); }
Initialize and call the parent
#private = 1;
Private class field
static create() {}
Static method on the class
get value() {}
Getter accessor
export default fn;
Default module export
export { a, b };
Named module exports
import x, { y } from './m.js'
Default + named imports
const m = await import('./m.js')
Dynamic import

ไม่มีรายการที่ตรงกับ “:q”


เกี่ยวกับ ชีตสรุป JavaScript

เอกสารสรุป JavaScript นี้เป็นข้อมูลอ้างอิงหน้าเดียวที่ค้นหาได้สำหรับภาษาสมัยใหม่: ตัวแปรและชนิดข้อมูล ฟังก์ชัน string อาร์เรย์ อ็อบเจ็กต์ async และ promise การควบคุมโฟลว์ DOM และเหตุการณ์ รวมถึงคลาสและโมดูล แต่ละรายการจับคู่สนิปเป็ตโค้ดจริงกับคำอธิบายหนึ่งบรรทัดว่ามันทำอะไร

มันเขียนขึ้นสำหรับ JavaScript ที่ผู้คนใช้งานจริงในปัจจุบัน — let และ const, arrow function, destructuring, spread, optional chaining, template literal, async/await และ ES module — ทำให้มันเป็นตัวทบทวนที่รวดเร็วเมื่อคุณสลับกลับมาจากภาษาอื่น

เอกสารทั้งหมดโหลดฝั่ง client และใช้งานฟรี กรองแบบสดด้วยกล่องค้นหา ข้ามไปมาระหว่างส่วนต่าง ๆ จากสารบัญที่ติดอยู่บนหน้า คลิกสนิปเป็ตใด ๆ เพื่อคัดลอก และพิมพ์หน้าเพื่อเก็บไว้เป็นข้อมูลอ้างอิง JavaScript ข้างโต๊ะทำงาน

วิธีใช้ ชีตสรุป JavaScript

  1. เปิดเอกสารและไล่ดูรายการส่วน — ตั้งแต่ Variables & types ผ่าน DOM & events ไปจนถึง Classes & modules
  2. พิมพ์ลงในกล่องค้นหาเพื่อกรองทุกแถวแบบสด ตัวนับผลลัพธ์จะแสดงจำนวนสนิปเป็ตที่ตรงกัน
  3. ใช้สารบัญที่ติดอยู่บนหน้าเพื่อกระโดดไปยังส่วนอย่าง Async & promises โดยตรง
  4. คลิกสนิปเป็ตหรือไอคอนคัดลอกของมันเพื่อคัดลอกโค้ดไปยังคลิปบอร์ดของคุณ
  5. คลิก Print เพื่อพิมพ์สำเนาข้อมูลอ้างอิงทั้งหมดในรูปแบบที่เหมาะกับกระดาษ

คำถามที่พบบ่อย

เก้าส่วน: ตัวแปรและชนิดข้อมูล ฟังก์ชัน string อาร์เรย์ อ็อบเจ็กต์ async และ promise การควบคุมโฟลว์ DOM และเหตุการณ์ และคลาสและโมดูล — แต่ละส่วนเป็นสนิปเป็ตพร้อมคัดลอกพร้อมคำอธิบายสั้น ๆ

ใช่ สนิปเป็ตใช้ไวยากรณ์ปัจจุบัน — let/const, arrow function, destructuring, optional chaining, async/await, คลาส และ ES module — สะท้อน JavaScript แบบ ES2022+ แทนที่จะเป็นรูปแบบเก่า

ได้ การคลิกสนิปเป็ตโค้ดใด ๆ หรือไอคอนคัดลอกที่ปรากฏเมื่อวางเมาส์บนแถว จะนำไปวางในคลิปบอร์ดของคุณทันทีพร้อมข้อความยืนยัน "Copied!" สั้น ๆ

ได้ ปุ่ม Print จะสร้างเลย์เอาต์ที่สะอาดโดยตัดกล่องค้นหา การนำทาง และปุ่มต่าง ๆ ออก ดังนั้นหน้าที่พิมพ์จะมีเฉพาะสนิปเป็ตและคำอธิบายเท่านั้น

ใช่ ฟรี โหลดทั้งหมดในเบราว์เซอร์ของคุณ และไม่ต้องมีบัญชี

แชร์สิ่งนี้

การค้นหายอดนิยม
javascript cheat sheet js cheat sheet javascript array methods javascript string methods javascript promises and async await javascript object methods js dom methods javascript syntax reference
ต้องการความช่วยเหลือ?
พบปัญหากับเครื่องมือนี้หรือไม่? แจ้งทีมงานของเรา
รายงานปัญหา

เพิ่มเครื่องมือฟรีนี้ลงในเว็บไซต์ของคุณเอง — คัดลอกและวางโค้ดด้านล่าง