JS DOCS
STRING
Name
Description
Example
Output
.lengthDescription: Mengembalikan panjang string.
Example:
"hello".length
Output: 5
.lengthMengembalikan panjang string.
"hello".length
5
.charAt(index)Description: Mengembalikan karakter pada posisi index.
Example:
"hello".charAt(1)
Output: "e"
.charAt(index)Mengembalikan karakter pada posisi index.
"hello".charAt(1)
"e"
.at(index)Description: Mengembalikan karakter pada index. Bisa negatif.
Example:
"hello".at(-1)
Output: "o"
.at(index)Mengembalikan karakter pada index. Bisa negatif.
"hello".at(-1)
"o"
.concat(str)Description: Menggabungkan string.
Example:
"Hello".concat(" World")Output: "Hello World"
.concat(str)Menggabungkan string.
"Hello".concat(" World")"Hello World"
.includes(str)Description: Mengecek apakah string mengandung substring.
Example:
"hello".includes("ll")Output: true
.includes(str)Mengecek apakah string mengandung substring.
"hello".includes("ll")true
.indexOf(str)Description: Index pertama substring. -1 jika tidak ditemukan.
Example:
"hello".indexOf("l")Output: 2
.indexOf(str)Index pertama substring. -1 jika tidak ditemukan.
"hello".indexOf("l")2
.lastIndexOf(str)Description: Index terakhir substring. -1 jika tidak ditemukan.
Example:
"hello".lastIndexOf("l")Output: 3
.lastIndexOf(str)Index terakhir substring. -1 jika tidak ditemukan.
"hello".lastIndexOf("l")3
.slice(start, end)Description: Potong string. Support negatif.
Example:
"hello".slice(1, 3)
Output: "el"
.slice(start, end)Potong string. Support negatif.
"hello".slice(1, 3)
"el"
.substring(start, end)Description: Potong string dari start sampai end.
Example:
"hello".substring(1, 3)
Output: "el"
.substring(start, end)Potong string dari start sampai end.
"hello".substring(1, 3)
"el"
.substr(start, length)Description: Potong string mulai dari start sebanyak length karakter. (Deprecated)
Example:
"hello".substr(1, 3)
Output: "ell"
.substr(start, length)Potong string mulai dari start sebanyak length karakter. (Deprecated)
"hello".substr(1, 3)
"ell"
.toUpperCase()Description: Ubah ke huruf besar.
Example:
"hello".toUpperCase()
Output: "HELLO"
.toUpperCase()Ubah ke huruf besar.
"hello".toUpperCase()
"HELLO"
.toLowerCase()Description: Ubah ke huruf kecil.
Example:
"HELLO".toLowerCase()
Output: "hello"
.toLowerCase()Ubah ke huruf kecil.
"HELLO".toLowerCase()
"hello"
.trim()Description: Hapus spasi awal dan akhir.
Example:
" hi ".trim()
Output: "hi"
.trim()Hapus spasi awal dan akhir.
" hi ".trim()
"hi"
.trimStart()Description: Hapus spasi di awal.
Example:
" hi ".trimStart()
Output: "hi "
.trimStart()Hapus spasi di awal.
" hi ".trimStart()
"hi "
.trimEnd()Description: Hapus spasi di akhir.
Example:
" hi ".trimEnd()
Output: " hi"
.trimEnd()Hapus spasi di akhir.
" hi ".trimEnd()
" hi"
.split(separator)Description: Pecah string jadi array.
Example:
"a,b,c".split(",")Output: ["a","b","c"]
.split(separator)Pecah string jadi array.
"a,b,c".split(",")["a","b","c"]
.replace(old, new)Description: Ganti substring pertama ditemukan.
Example:
"haha".replace("ha", "he")Output: "heha"
.replace(old, new)Ganti substring pertama ditemukan.
"haha".replace("ha", "he")"heha"
.replaceAll(old, new)Description: Ganti semua substring.
Example:
"haha".replaceAll("ha", "he")Output: "hehe"
.replaceAll(old, new)Ganti semua substring.
"haha".replaceAll("ha", "he")"hehe"
.startsWith(str)Description: Mengecek apakah string diawali substring tertentu.
Example:
"hello".startsWith("he")Output: true
.startsWith(str)Mengecek apakah string diawali substring tertentu.
"hello".startsWith("he")true
.endsWith(str)Description: Mengecek apakah string diakhiri substring tertentu.
Example:
"hello".endsWith("lo")Output: true
.endsWith(str)Mengecek apakah string diakhiri substring tertentu.
"hello".endsWith("lo")true
.padStart(targetLength, padString)Description: Menambah karakter di awal sampai panjang tertentu.
Example:
"5".padStart(3, "0")
Output: "005"
.padStart(targetLength, padString)Menambah karakter di awal sampai panjang tertentu.
"5".padStart(3, "0")
"005"
.padEnd(targetLength, padString)Description: Menambah karakter di akhir sampai panjang tertentu.
Example:
"5".padEnd(3, "0")
Output: "500"
.padEnd(targetLength, padString)Menambah karakter di akhir sampai panjang tertentu.
"5".padEnd(3, "0")
"500"
.repeat(count)Description: Mengulang string beberapa kali.
Example:
"ha".repeat(3)
Output: "hahaha"
.repeat(count)Mengulang string beberapa kali.
"ha".repeat(3)
"hahaha"
.match(regex)Description: Mencari kecocokan string dengan regex.
Example:
"hello".match(/l/g)
Output: ["l","l"]
.match(regex)Mencari kecocokan string dengan regex.
"hello".match(/l/g)
["l","l"]
.matchAll(regex)Description: Mencari semua kecocokan regex (iterator).
Example:
for (const m of "hello".matchAll(/l/g)) console.log(m)
Output: iterator
.matchAll(regex)Mencari semua kecocokan regex (iterator).
for (const m of "hello".matchAll(/l/g)) console.log(m)
iterator
.search(regex)Description: Mencari index pertama yang cocok dengan regex.
Example:
"hello".search(/ll/)
Output: 2
.search(regex)Mencari index pertama yang cocok dengan regex.
"hello".search(/ll/)
2
ARRAY — STATIC
Name
Description
Example
Output
Array.from(iterable)Description: Membuat array dari iterable atau array-like.
Example:
Array.from('hello')Output: ['h','e','l','l','o']
Array.from(iterable)Membuat array dari iterable atau array-like.
Array.from('hello')['h','e','l','l','o']
Array.isArray(val)Description: Mengecek apakah nilai adalah array.
Example:
Array.isArray([1,2])
Output: true
Array.isArray(val)Mengecek apakah nilai adalah array.
Array.isArray([1,2])
true
Array.of(...items)Description: Membuat array dari argumen.
Example:
Array.of(1,2,3)
Output: [1,2,3]
Array.of(...items)Membuat array dari argumen.
Array.of(1,2,3)
[1,2,3]
ARRAY — INSTANCE
Name
Description
Example
Output
.lengthDescription: Jumlah elemen array.
Example:
[1,2,3].length
Output: 3
.lengthJumlah elemen array.
[1,2,3].length
3
.push(item)Description: Tambah elemen ke akhir. (Mutasi)
Example:
const arr = [1]; arr.push(2); arr
Output: [1, 2]
.push(item)Tambah elemen ke akhir. (Mutasi)
const arr = [1]; arr.push(2); arr
[1, 2]
.pop()Description: Hapus elemen terakhir. (Mutasi)
Example:
const arr = [1,2]; arr.pop(); arr
Output: [1]
.pop()Hapus elemen terakhir. (Mutasi)
const arr = [1,2]; arr.pop(); arr
[1]
.shift()Description: Hapus elemen pertama. (Mutasi)
Example:
const arr = [1,2]; arr.shift(); arr
Output: [2]
.shift()Hapus elemen pertama. (Mutasi)
const arr = [1,2]; arr.shift(); arr
[2]
.unshift(item)Description: Tambah elemen ke awal. (Mutasi)
Example:
const arr = [2]; arr.unshift(1); arr
Output: [1, 2]
.unshift(item)Tambah elemen ke awal. (Mutasi)
const arr = [2]; arr.unshift(1); arr
[1, 2]
.splice(start, deleteCount, ...items)Description: Menghapus/menambah elemen di tengah. (Mutasi)
Example:
const arr = [1,2,3]; arr.splice(1,1); arr
Output: [1,3]
.splice(start, deleteCount, ...items)Menghapus/menambah elemen di tengah. (Mutasi)
const arr = [1,2,3]; arr.splice(1,1); arr
[1,3]
.reverse()Description: Membalik urutan array. (Mutasi)
Example:
const arr = [1,2,3]; arr.reverse(); arr
Output: [3,2,1]
.reverse()Membalik urutan array. (Mutasi)
const arr = [1,2,3]; arr.reverse(); arr
[3,2,1]
.sort(compareFn)Description: Mengurutkan array. (Mutasi)
Example:
const arr = [3,1,2]; arr.sort((a,b) => a-b); arr
Output: [1,2,3]
.sort(compareFn)Mengurutkan array. (Mutasi)
const arr = [3,1,2]; arr.sort((a,b) => a-b); arr
[1,2,3]
.fill(value, start?, end?)Description: Mengisi elemen dengan nilai statis. (Mutasi)
Example:
const arr = [1,2,3]; arr.fill(0, 1, 3); arr
Output: [1,0,0]
.fill(value, start?, end?)Mengisi elemen dengan nilai statis. (Mutasi)
const arr = [1,2,3]; arr.fill(0, 1, 3); arr
[1,0,0]
.copyWithin(target, start, end?)Description: Salin bagian array ke posisi lain. (Mutasi)
Example:
const arr = [1,2,3,4]; arr.copyWithin(0, 2); arr
Output: [3,4,3,4]
.copyWithin(target, start, end?)Salin bagian array ke posisi lain. (Mutasi)
const arr = [1,2,3,4]; arr.copyWithin(0, 2); arr
[3,4,3,4]
.map(cb)Description: Transform tiap elemen, return array baru.
Example:
[1,2].map(v => v*2)
Output: [2,4]
.map(cb)Transform tiap elemen, return array baru.
[1,2].map(v => v*2)
[2,4]
.filter(cb)Description: Filter elemen, return array baru.
Example:
[1,2,3].filter(v => v>1)
Output: [2,3]
.filter(cb)Filter elemen, return array baru.
[1,2,3].filter(v => v>1)
[2,3]
.find(cb)Description: Cari elemen pertama yang cocok.
Example:
[{id:1},{id:2}].find(v => v.id>1)Output: {id:2}
.find(cb)Cari elemen pertama yang cocok.
[{id:1},{id:2}].find(v => v.id>1){id:2}
.findIndex(cb)Description: Cari index elemen pertama yang cocok.
Example:
[{id:1},{id:2}].findIndex(v => v.id>1)Output: 1
.findIndex(cb)Cari index elemen pertama yang cocok.
[{id:1},{id:2}].findIndex(v => v.id>1)1
.findLast(cb)Description: Cari elemen terakhir yang cocok.
Example:
[1,2,3,2].findLast(v => v===2)
Output: 2
.findLast(cb)Cari elemen terakhir yang cocok.
[1,2,3,2].findLast(v => v===2)
2
.findLastIndex(cb)Description: Cari index elemen terakhir yang cocok.
Example:
[1,2,3,2].findLastIndex(v => v===2)
Output: 3
.findLastIndex(cb)Cari index elemen terakhir yang cocok.
[1,2,3,2].findLastIndex(v => v===2)
3
.reduce(cb, init?)Description: Akumulasi nilai. cb(acc, val, idx, arr).
Example:
[1,2,3].reduce((sum, v) => sum+v, 0)
Output: 6
.reduce(cb, init?)Akumulasi nilai. cb(acc, val, idx, arr).
[1,2,3].reduce((sum, v) => sum+v, 0)
6
.reduceRight(cb, init?)Description: Akumulasi dari kanan.
Example:
[[1,2],[3,4]].reduceRight((flat, arr) => flat.concat(arr), [])
Output: [3,4,1,2]
.reduceRight(cb, init?)Akumulasi dari kanan.
[[1,2],[3,4]].reduceRight((flat, arr) => flat.concat(arr), [])
[3,4,1,2]
.forEach(cb)Description: Menjalankan fungsi untuk setiap elemen. Tidak menghasilkan array baru.
Example:
[1,2].forEach(v => console.log(v))
Output: void
.forEach(cb)Menjalankan fungsi untuk setiap elemen. Tidak menghasilkan array baru.
[1,2].forEach(v => console.log(v))
void
.some(cb)Description: Cek apakah minimal satu elemen cocok.
Example:
[1,2,3].some(v => v>2)
Output: true
.some(cb)Cek apakah minimal satu elemen cocok.
[1,2,3].some(v => v>2)
true
.every(cb)Description: Cek apakah semua elemen cocok.
Example:
[1,2,3].every(v => v>0)
Output: true
.every(cb)Cek apakah semua elemen cocok.
[1,2,3].every(v => v>0)
true
.includes(item)Description: Mengecek apakah array mengandung elemen tertentu.
Example:
[1,2,3].includes(2)
Output: true
.includes(item)Mengecek apakah array mengandung elemen tertentu.
[1,2,3].includes(2)
true
.indexOf(item)Description: Index pertama elemen. -1 jika tidak ditemukan.
Example:
[1,2,3].indexOf(2)
Output: 1
.indexOf(item)Index pertama elemen. -1 jika tidak ditemukan.
[1,2,3].indexOf(2)
1
.lastIndexOf(item)Description: Index terakhir elemen. -1 jika tidak ditemukan.
Example:
[1,2,3,2].lastIndexOf(2)
Output: 3
.lastIndexOf(item)Index terakhir elemen. -1 jika tidak ditemukan.
[1,2,3,2].lastIndexOf(2)
3
.slice(start?, end?)Description: Potong array, return array baru.
Example:
[1,2,3].slice(0, 2)
Output: [1,2]
.slice(start?, end?)Potong array, return array baru.
[1,2,3].slice(0, 2)
[1,2]
.concat(arr)Description: Menggabungkan array, return array baru.
Example:
[1,2].concat([3,4])
Output: [1,2,3,4]
.concat(arr)Menggabungkan array, return array baru.
[1,2].concat([3,4])
[1,2,3,4]
.join(separator)Description: Menggabungkan array menjadi string.
Example:
['a','b'].join('-')Output: "a-b"
.join(separator)Menggabungkan array menjadi string.
['a','b'].join('-')"a-b"
.flat(depth?)Description: Meratakan array bertingkat.
Example:
[1,[2,[3]]].flat(2)
Output: [1,2,3]
.flat(depth?)Meratakan array bertingkat.
[1,[2,[3]]].flat(2)
[1,2,3]
.flatMap(cb)Description: Map lalu flat satu tingkat.
Example:
[1,2].flatMap(v => [v, v*2])
Output: [1,2,2,4]
.flatMap(cb)Map lalu flat satu tingkat.
[1,2].flatMap(v => [v, v*2])
[1,2,2,4]
.entries()Description: Iterator pasangan [index, value].
Example:
for (const [i,v] of ['a','b'].entries()) console.log(i,v)
Output: 0 'a' , 1 'b'
.entries()Iterator pasangan [index, value].
for (const [i,v] of ['a','b'].entries()) console.log(i,v)
0 'a' , 1 'b'
.keys()Description: Iterator index.
Example:
Array.from(['a','b'].keys())
Output: [0,1]
.keys()Iterator index.
Array.from(['a','b'].keys())
[0,1]
.values()Description: Iterator nilai.
Example:
Array.from(['a','b'].values())
Output: ['a','b']
.values()Iterator nilai.
Array.from(['a','b'].values())
['a','b']
OBJECT
Name
Description
Example
Output
Object.keys(obj)Description: Array dari semua key.
Example:
Object.keys({a:1,b:2})Output: ["a","b"]
Object.keys(obj)Array dari semua key.
Object.keys({a:1,b:2})["a","b"]
Object.values(obj)Description: Array dari semua value.
Example:
Object.values({a:1,b:2})Output: [1, 2]
Object.values(obj)Array dari semua value.
Object.values({a:1,b:2})[1, 2]
Object.entries(obj)Description: Array pasangan [key, value].
Example:
Object.entries({a:1})Output: [["a", 1]]
Object.entries(obj)Array pasangan [key, value].
Object.entries({a:1})[["a", 1]]
Object.assign(target, src)Description: Copy properti ke target.
Example:
Object.assign({}, {a:1})Output: {a: 1}
Object.assign(target, src)Copy properti ke target.
Object.assign({}, {a:1}){a: 1}
Object.fromEntries(entries)Description: Ubah array entries jadi object.
Example:
Object.fromEntries([["a", 1]])
Output: {a: 1}
Object.fromEntries(entries)Ubah array entries jadi object.
Object.fromEntries([["a", 1]])
{a: 1}
Object.hasOwn(obj, prop)Description: Cek properti milik sendiri (modern).
Example:
Object.hasOwn({a:1}, 'a')Output: true
Object.hasOwn(obj, prop)Cek properti milik sendiri (modern).
Object.hasOwn({a:1}, 'a')true
Object.freeze(obj)Description: Membekukan object (tidak bisa diubah).
Example:
const obj = Object.freeze({a:1}); obj.a = 2; obj.aOutput: 1
Object.freeze(obj)Membekukan object (tidak bisa diubah).
const obj = Object.freeze({a:1}); obj.a = 2; obj.a1
Object.seal(obj)Description: Menyegel object (properti tidak bisa ditambah/hapus).
Example:
const obj = Object.seal({a:1}); delete obj.a; obj.aOutput: 1
Object.seal(obj)Menyegel object (properti tidak bisa ditambah/hapus).
const obj = Object.seal({a:1}); delete obj.a; obj.a1
Object.create(proto)Description: Membuat object baru dengan prototipe tertentu.
Example:
Object.create(null)
Output: {} (tanpa prototype)
Object.create(proto)Membuat object baru dengan prototipe tertentu.
Object.create(null)
{} (tanpa prototype)
NUMBER
Name
Description
Example
Output
Number.isInteger(val)Description: Cek bilangan bulat.
Example:
Number.isInteger(5)
Output: true
Number.isInteger(val)Cek bilangan bulat.
Number.isInteger(5)
true
Number.parseInt(str)Description: Ubah string ke integer.
Example:
Number.parseInt("42px")Output: 42
Number.parseInt(str)Ubah string ke integer.
Number.parseInt("42px")42
Number.parseFloat(str)Description: Ubah string ke float.
Example:
Number.parseFloat("3.14px")Output: 3.14
Number.parseFloat(str)Ubah string ke float.
Number.parseFloat("3.14px")3.14
.toFixed(digits)Description: Format desimal menjadi string.
Example:
(3.14159).toFixed(2)
Output: "3.14"
.toFixed(digits)Format desimal menjadi string.
(3.14159).toFixed(2)
"3.14"
.toPrecision(digits)Description: Format angka ke panjang signifikan.
Example:
(3.14159).toPrecision(2)
Output: "3.1"
.toPrecision(digits)Format angka ke panjang signifikan.
(3.14159).toPrecision(2)
"3.1"
MATH
Name
Description
Example
Output
Math.PIDescription: Nilai pi.
Example:
Math.PI
Output: 3.14159...
Math.PINilai pi.
Math.PI
3.14159...
Math.floor(x)Description: Bulatkan ke bawah.
Example:
Math.floor(3.9)
Output: 3
Math.floor(x)Bulatkan ke bawah.
Math.floor(3.9)
3
Math.ceil(x)Description: Bulatkan ke atas.
Example:
Math.ceil(3.1)
Output: 4
Math.ceil(x)Bulatkan ke atas.
Math.ceil(3.1)
4
Math.round(x)Description: Bulatkan ke terdekat.
Example:
Math.round(3.5)
Output: 4
Math.round(x)Bulatkan ke terdekat.
Math.round(3.5)
4
Math.abs(x)Description: Nilai mutlak.
Example:
Math.abs(-5)
Output: 5
Math.abs(x)Nilai mutlak.
Math.abs(-5)
5
Math.random()Description: Random 0 sampai <1.
Example:
Math.random()
Output: 0.1234...
Math.random()Random 0 sampai <1.
Math.random()
0.1234...
Math.max(...nums)Description: Nilai terbesar.
Example:
Math.max(1,5,3)
Output: 5
Math.max(...nums)Nilai terbesar.
Math.max(1,5,3)
5
Math.min(...nums)Description: Nilai terkecil.
Example:
Math.min(1,5,3)
Output: 1
Math.min(...nums)Nilai terkecil.
Math.min(1,5,3)
1
Math.sqrt(x)Description: Akar kuadrat.
Example:
Math.sqrt(9)
Output: 3
Math.sqrt(x)Akar kuadrat.
Math.sqrt(9)
3
Math.pow(x, y)Description: Pangkat.
Example:
Math.pow(2, 3)
Output: 8
Math.pow(x, y)Pangkat.
Math.pow(2, 3)
8
Math.trunc(x)Description: Buang desimal tanpa pembulatan.
Example:
Math.trunc(3.9)
Output: 3
Math.trunc(x)Buang desimal tanpa pembulatan.
Math.trunc(3.9)
3
MAP
Name
Description
Example
Output
new Map()Description: Membuat map baru.
Example:
new Map()
Output: Map(0)
new Map()Membuat map baru.
new Map()
Map(0)
.set(key, value)Description: Menambah atau mengubah pasangan kunci-nilai.
Example:
const m = new Map(); m.set('a',1)Output: Map(1)
.set(key, value)Menambah atau mengubah pasangan kunci-nilai.
const m = new Map(); m.set('a',1)Map(1)
.get(key)Description: Mengambil nilai berdasarkan kunci.
Example:
m.get('a')Output: 1
.get(key)Mengambil nilai berdasarkan kunci.
m.get('a')1
.has(key)Description: Mengecek keberadaan kunci.
Example:
m.has('a')Output: true
.has(key)Mengecek keberadaan kunci.
m.has('a')true
.delete(key)Description: Menghapus kunci.
Example:
m.delete('a')Output: true
.delete(key)Menghapus kunci.
m.delete('a')true
.clear()Description: Menghapus semua pasangan.
Example:
m.clear()
Output: void
.clear()Menghapus semua pasangan.
m.clear()
void
.sizeDescription: Jumlah pasangan kunci-nilai.
Example:
m.size
Output: 0
.sizeJumlah pasangan kunci-nilai.
m.size
0
.forEach(cb)Description: Iterasi dengan callback.
Example:
m.forEach((v,k) => console.log(k,v))
Output: void
.forEach(cb)Iterasi dengan callback.
m.forEach((v,k) => console.log(k,v))
void
.keys()Description: Iterator kunci.
Example:
Array.from(m.keys())
Output: ['a']
.keys()Iterator kunci.
Array.from(m.keys())
['a']
.values()Description: Iterator nilai.
Example:
Array.from(m.values())
Output: [1]
.values()Iterator nilai.
Array.from(m.values())
[1]
SET
Name
Description
Example
Output
new Set()Description: Membuat set baru.
Example:
new Set()
Output: Set(0)
new Set()Membuat set baru.
new Set()
Set(0)
.add(value)Description: Menambah nilai unik.
Example:
const s = new Set(); s.add(1)
Output: Set(1)
.add(value)Menambah nilai unik.
const s = new Set(); s.add(1)
Set(1)
.has(value)Description: Mengecek keberadaan nilai.
Example:
s.has(1)
Output: true
.has(value)Mengecek keberadaan nilai.
s.has(1)
true
.delete(value)Description: Menghapus nilai.
Example:
s.delete(1)
Output: true
.delete(value)Menghapus nilai.
s.delete(1)
true
.clear()Description: Menghapus semua nilai.
Example:
s.clear()
Output: void
.clear()Menghapus semua nilai.
s.clear()
void
.sizeDescription: Jumlah nilai.
Example:
s.size
Output: 0
.sizeJumlah nilai.
s.size
0
PROMISE
Name
Description
Example
Output
new Promise(executor)Description: Membuat promise.
Example:
new Promise((resolve) => resolve(1))
Output: Promise{1}
new Promise(executor)Membuat promise.
new Promise((resolve) => resolve(1))
Promise{1}
Promise.resolve(val)Description: Promise sukses langsung.
Example:
Promise.resolve(42)
Output: Promise{42}
Promise.resolve(val)Promise sukses langsung.
Promise.resolve(42)
Promise{42}
Promise.reject(err)Description: Promise gagal langsung.
Example:
Promise.reject('error')Output: Promise{<rejected>}
Promise.reject(err)Promise gagal langsung.
Promise.reject('error')Promise{<rejected>}
.then(onFulfilled, onRejected?)Description: Menangani hasil sukses.
Example:
Promise.resolve(1).then(v => v+1)
Output: Promise{2}
.then(onFulfilled, onRejected?)Menangani hasil sukses.
Promise.resolve(1).then(v => v+1)
Promise{2}
.catch(onRejected)Description: Menangani error.
Example:
Promise.reject('err').catch(e => e)Output: Promise{'err'}
.catch(onRejected)Menangani error.
Promise.reject('err').catch(e => e)Promise{'err'}
.finally(onFinally)Description: Dijalankan apapun hasilnya.
Example:
Promise.resolve().finally(() => console.log('done'))Output: void
.finally(onFinally)Dijalankan apapun hasilnya.
Promise.resolve().finally(() => console.log('done'))void
Promise.all([...])Description: Tunggu semua selesai, error jika ada yang gagal.
Example:
Promise.all([Promise.resolve(1), Promise.resolve(2)])
Output: Promise{[1,2]}
Promise.all([...])Tunggu semua selesai, error jika ada yang gagal.
Promise.all([Promise.resolve(1), Promise.resolve(2)])
Promise{[1,2]}
Promise.allSettled([...])Description: Tunggu semua selesai (selalu sukses).
Example:
Promise.allSettled([Promise.reject('e')])Output: Promise{[{status:'rejected', reason:'e'}]}
Promise.allSettled([...])Tunggu semua selesai (selalu sukses).
Promise.allSettled([Promise.reject('e')])Promise{[{status:'rejected', reason:'e'}]}
Promise.race([...])Description: Hasil dari promise pertama yang selesai.
Example:
Promise.race([new Promise(r => setTimeout(r,100,'a')), Promise.resolve('b')])Output: Promise{'b'}
Promise.race([...])Hasil dari promise pertama yang selesai.
Promise.race([new Promise(r => setTimeout(r,100,'a')), Promise.resolve('b')])Promise{'b'}
Promise.any([...])Description: Promise pertama yang sukses, error jika semua gagal.
Example:
Promise.any([Promise.reject('e'), Promise.resolve(2)])Output: Promise{2}
Promise.any([...])Promise pertama yang sukses, error jika semua gagal.
Promise.any([Promise.reject('e'), Promise.resolve(2)])Promise{2}
DATE
Name
Description
Example
Output
new Date()Description: Tanggal & waktu saat ini.
Example:
new Date()
Output: 2026-01-01T00:00:00.000Z
new Date()Tanggal & waktu saat ini.
new Date()
2026-01-01T00:00:00.000Z
new Date(timestamp)Description: Dari milliseconds sejak epoch.
Example:
new Date(0)
Output: 1970-01-01T00:00:00.000Z
new Date(timestamp)Dari milliseconds sejak epoch.
new Date(0)
1970-01-01T00:00:00.000Z
new Date(dateString)Description: Parsing string tanggal.
Example:
new Date('2026-01-01')Output: 2026-01-01T00:00:00.000Z
new Date(dateString)Parsing string tanggal.
new Date('2026-01-01')2026-01-01T00:00:00.000Z
.getFullYear()Description: Tahun (4 digit).
Example:
new Date().getFullYear()
Output: 2026
.getFullYear()Tahun (4 digit).
new Date().getFullYear()
2026
.getMonth()Description: Bulan (0-11).
Example:
new Date(2026,0,1).getMonth()
Output: 0
.getMonth()Bulan (0-11).
new Date(2026,0,1).getMonth()
0
.getDate()Description: Tanggal (1-31).
Example:
new Date(2026,0,1).getDate()
Output: 1
.getDate()Tanggal (1-31).
new Date(2026,0,1).getDate()
1
.getHours()Description: Jam (0-23).
Example:
new Date(2026,0,1,13).getHours()
Output: 13
.getHours()Jam (0-23).
new Date(2026,0,1,13).getHours()
13
.getMinutes()Description: Menit (0-59).
Example:
new Date(2026,0,1,0,30).getMinutes()
Output: 30
.getMinutes()Menit (0-59).
new Date(2026,0,1,0,30).getMinutes()
30
.getSeconds()Description: Detik (0-59).
Example:
new Date(2026,0,1,0,0,45).getSeconds()
Output: 45
.getSeconds()Detik (0-59).
new Date(2026,0,1,0,0,45).getSeconds()
45
.toISOString()Description: Format ISO 8601.
Example:
new Date(2026,0,1).toISOString()
Output: "2026-01-01T00:00:00.000Z"
.toISOString()Format ISO 8601.
new Date(2026,0,1).toISOString()
"2026-01-01T00:00:00.000Z"
.toLocaleDateString(locale)Description: Format tanggal lokal.
Example:
new Date(2026,0,1).toLocaleDateString('id-ID')Output: "1/1/2026"
.toLocaleDateString(locale)Format tanggal lokal.
new Date(2026,0,1).toLocaleDateString('id-ID')"1/1/2026"
DOM-SELECTION
Name
Description
Example
Output
document.querySelector(selector)Description: Ambil elemen pertama yang cocok.
Example:
document.querySelector('.card')Output: Element | null
document.querySelector(selector)Ambil elemen pertama yang cocok.
document.querySelector('.card')Element | null
document.querySelectorAll(selector)Description: Ambil semua elemen yang cocok (NodeList).
Example:
document.querySelectorAll('.card')Output: NodeList
document.querySelectorAll(selector)Ambil semua elemen yang cocok (NodeList).
document.querySelectorAll('.card')NodeList
document.getElementById(id)Description: Ambil elemen berdasarkan id.
Example:
document.getElementById('app')Output: Element | null
document.getElementById(id)Ambil elemen berdasarkan id.
document.getElementById('app')Element | null
document.getElementsByClassName(class)Description: Ambil elemen berdasarkan class (HTMLCollection live).
Example:
document.getElementsByClassName('item')Output: HTMLCollection
document.getElementsByClassName(class)Ambil elemen berdasarkan class (HTMLCollection live).
document.getElementsByClassName('item')HTMLCollection
document.getElementsByTagName(tag)Description: Ambil elemen berdasarkan tag (HTMLCollection live).
Example:
document.getElementsByTagName('p')Output: HTMLCollection
document.getElementsByTagName(tag)Ambil elemen berdasarkan tag (HTMLCollection live).
document.getElementsByTagName('p')HTMLCollection
DOM-MANIPULATION
Name
Description
Example
Output
document.createElement(tag)Description: Buat elemen baru.
Example:
document.createElement('div')Output: Element
document.createElement(tag)Buat elemen baru.
document.createElement('div')Element
.appendChild(node)Description: Tambah node sebagai anak terakhir.
Example:
parent.appendChild(child)
Output: Node
.appendChild(node)Tambah node sebagai anak terakhir.
parent.appendChild(child)
Node
.append(...nodes)Description: Tambah node atau teks di akhir.
Example:
parent.append('Hello', child)Output: void
.append(...nodes)Tambah node atau teks di akhir.
parent.append('Hello', child)void
.prepend(...nodes)Description: Tambah node atau teks di awal.
Example:
parent.prepend(child)
Output: void
.prepend(...nodes)Tambah node atau teks di awal.
parent.prepend(child)
void
.remove()Description: Hapus elemen dari DOM.
Example:
element.remove()
Output: void
.remove()Hapus elemen dari DOM.
element.remove()
void
.replaceChild(newChild, oldChild)Description: Ganti child lama dengan child baru.
Example:
parent.replaceChild(newNode, oldNode)
Output: Node
.replaceChild(newChild, oldChild)Ganti child lama dengan child baru.
parent.replaceChild(newNode, oldNode)
Node
.innerHTMLDescription: Isi HTML dalam elemen (bisa diset/dibaca).
Example:
element.innerHTML = '<p>Hi</p>'
Output: string
.innerHTMLIsi HTML dalam elemen (bisa diset/dibaca).
element.innerHTML = '<p>Hi</p>'
string
.innerTextDescription: Teks yang terlihat (mempertimbangkan CSS).
Example:
element.innerText = 'Hi'
Output: string
.innerTextTeks yang terlihat (mempertimbangkan CSS).
element.innerText = 'Hi'
string
.textContentDescription: Semua teks di dalam elemen.
Example:
element.textContent = 'Hi'
Output: string
.textContentSemua teks di dalam elemen.
element.textContent = 'Hi'
string
.classListDescription: Objek untuk mengelola class (add, remove, toggle, contains).
Example:
element.classList.add('active')Output: DOMTokenList
.classListObjek untuk mengelola class (add, remove, toggle, contains).
element.classList.add('active')DOMTokenList
.setAttribute(name, value)Description: Menambah/mengubah atribut.
Example:
element.setAttribute('data-id', '1')Output: void
.setAttribute(name, value)Menambah/mengubah atribut.
element.setAttribute('data-id', '1')void
.getAttribute(name)Description: Mengambil nilai atribut.
Example:
element.getAttribute('data-id')Output: "1"
.getAttribute(name)Mengambil nilai atribut.
element.getAttribute('data-id')"1"
.removeAttribute(name)Description: Menghapus atribut.
Example:
element.removeAttribute('data-id')Output: void
.removeAttribute(name)Menghapus atribut.
element.removeAttribute('data-id')void
.styleDescription: Mengubah/membaca inline style.
Example:
element.style.color = 'red'
Output: void
.styleMengubah/membaca inline style.
element.style.color = 'red'
void
EVENT
Name
Description
Example
Output
.addEventListener(event, handler)Description: Pasang event listener.
Example:
btn.addEventListener('click', () => {})Output: void
.addEventListener(event, handler)Pasang event listener.
btn.addEventListener('click', () => {})void
.removeEventListener(event, handler)Description: Lepas event listener.
Example:
btn.removeEventListener('click', handler)Output: void
.removeEventListener(event, handler)Lepas event listener.
btn.removeEventListener('click', handler)void
.preventDefault()Description: Cegah aksi default browser.
Example:
event.preventDefault()
Output: void
.preventDefault()Cegah aksi default browser.
event.preventDefault()
void
clickDescription: Saat elemen diklik.
Example:
element.addEventListener('click', ...)Output: event
clickSaat elemen diklik.
element.addEventListener('click', ...)event
inputDescription: Saat nilai input berubah (setiap ketik).
Example:
input.addEventListener('input', ...)Output: event
inputSaat nilai input berubah (setiap ketik).
input.addEventListener('input', ...)event
changeDescription: Saat nilai input berubah dan fokus hilang.
Example:
select.addEventListener('change', ...)Output: event
changeSaat nilai input berubah dan fokus hilang.
select.addEventListener('change', ...)event
submitDescription: Saat form dikirim.
Example:
form.addEventListener('submit', ...)Output: event
submitSaat form dikirim.
form.addEventListener('submit', ...)event
keydownDescription: Tombol keyboard ditekan.
Example:
document.addEventListener('keydown', ...)Output: event
keydownTombol keyboard ditekan.
document.addEventListener('keydown', ...)event
keyupDescription: Tombol keyboard dilepas.
Example:
document.addEventListener('keyup', ...)Output: event
keyupTombol keyboard dilepas.
document.addEventListener('keyup', ...)event
BOM
Name
Description
Example
Output
alert(msg)Description: Tampilkan dialog alert.
Example:
alert('Hello')Output: void
alert(msg)Tampilkan dialog alert.
alert('Hello')void
confirm(msg)Description: Dialog konfirmasi (OK/Cancel).
Example:
confirm('Yakin?')Output: boolean
confirm(msg)Dialog konfirmasi (OK/Cancel).
confirm('Yakin?')boolean
prompt(msg, default?)Description: Minta input teks.
Example:
prompt('Nama?')Output: string | null
prompt(msg, default?)Minta input teks.
prompt('Nama?')string | null
setTimeout(cb, delay)Description: Jalankan fungsi setelah delay ms.
Example:
setTimeout(() => {}, 1000)Output: timer id
setTimeout(cb, delay)Jalankan fungsi setelah delay ms.
setTimeout(() => {}, 1000)timer id
setInterval(cb, delay)Description: Jalankan fungsi berulang tiap delay ms.
Example:
setInterval(() => {}, 1000)Output: timer id
setInterval(cb, delay)Jalankan fungsi berulang tiap delay ms.
setInterval(() => {}, 1000)timer id
clearTimeout(id)Description: Hentikan timeout.
Example:
clearTimeout(id)
Output: void
clearTimeout(id)Hentikan timeout.
clearTimeout(id)
void
clearInterval(id)Description: Hentikan interval.
Example:
clearInterval(id)
Output: void
clearInterval(id)Hentikan interval.
clearInterval(id)
void
locationDescription: Objek URL (href, reload, replace).
Example:
location.href = '/new-page'
Output: void
locationObjek URL (href, reload, replace).
location.href = '/new-page'
void
historyDescription: Riwayat navigasi (back, forward, go).
Example:
history.back()
Output: void
historyRiwayat navigasi (back, forward, go).
history.back()
void
navigatorDescription: Info browser & perangkat (userAgent, clipboard).
Example:
navigator.userAgent
Output: string
navigatorInfo browser & perangkat (userAgent, clipboard).
navigator.userAgent
string
JSON
Name
Description
Example
Output
JSON.stringify(value)Description: Ubah nilai JS ke JSON string.
Example:
JSON.stringify({a:1})Output: {"a":1}
JSON.stringify(value)Ubah nilai JS ke JSON string.
JSON.stringify({a:1}){"a":1}
JSON.parse(text)Description: Ubah JSON string ke nilai JS.
Example:
JSON.parse('{"a":1}')Output: {a:1}
JSON.parse(text)Ubah JSON string ke nilai JS.
JSON.parse('{"a":1}'){a:1}
STORAGE
Name
Description
Example
Output
localStorage.setItem(key, val)Description: Simpan string ke localStorage.
Example:
localStorage.setItem('name', 'Ridho')Output: void
localStorage.setItem(key, val)Simpan string ke localStorage.
localStorage.setItem('name', 'Ridho')void
localStorage.getItem(key)Description: Baca string dari localStorage.
Example:
localStorage.getItem('name')Output: "Ridho"
localStorage.getItem(key)Baca string dari localStorage.
localStorage.getItem('name')"Ridho"
localStorage.removeItem(key)Description: Hapus item.
Example:
localStorage.removeItem('name')Output: void
localStorage.removeItem(key)Hapus item.
localStorage.removeItem('name')void
localStorage.clear()Description: Hapus semua.
Example:
localStorage.clear()
Output: void
localStorage.clear()Hapus semua.
localStorage.clear()
void
sessionStorage.setItem(key, val)Description: Simpan string ke sessionStorage.
Example:
sessionStorage.setItem('token', 'abc')Output: void
sessionStorage.setItem(key, val)Simpan string ke sessionStorage.
sessionStorage.setItem('token', 'abc')void
sessionStorage.getItem(key)Description: Baca string dari sessionStorage.
Example:
sessionStorage.getItem('token')Output: "abc"
sessionStorage.getItem(key)Baca string dari sessionStorage.
sessionStorage.getItem('token')"abc"
sessionStorage.removeItem(key)Description: Hapus item.
Example:
sessionStorage.removeItem('token')Output: void
sessionStorage.removeItem(key)Hapus item.
sessionStorage.removeItem('token')void
sessionStorage.clear()Description: Hapus semua.
Example:
sessionStorage.clear()
Output: void
sessionStorage.clear()Hapus semua.
sessionStorage.clear()
void
CONSOLE
Name
Description
Example
Output
console.log(...args)Description: Cetak pesan biasa.
Example:
console.log('Hello', 123)Output: Hello 123
console.log(...args)Cetak pesan biasa.
console.log('Hello', 123)Hello 123
console.table(data)Description: Cetak data dalam bentuk tabel.
Example:
console.table([{a:1},{a:2}])Output: Tabel
console.table(data)Cetak data dalam bentuk tabel.
console.table([{a:1},{a:2}])Tabel
console.error(...args)Description: Cetak pesan error (warna merah).
Example:
console.error('Gagal!')Output: Gagal!
console.error(...args)Cetak pesan error (warna merah).
console.error('Gagal!')Gagal!
console.warn(...args)Description: Cetak peringatan (kuning).
Example:
console.warn('Hati-hati')Output: Hati-hati
console.warn(...args)Cetak peringatan (kuning).
console.warn('Hati-hati')Hati-hati
console.group(label)Description: Mulai grup log.
Example:
console.group('Detail')Output: void
console.group(label)Mulai grup log.
console.group('Detail')void
console.groupEnd()Description: Akhiri grup log.
Example:
console.groupEnd()
Output: void
console.groupEnd()Akhiri grup log.
console.groupEnd()
void
FETCH
Name
Description
Example
Output
fetch(url, options?)Description: Kirim HTTP request.
Example:
fetch('/api/users')Output: Promise<Response>
fetch(url, options?)Kirim HTTP request.
fetch('/api/users')Promise<Response>
response.json()Description: Parse body sebagai JSON.
Example:
fetch('/api').then(r => r.json())Output: Promise<any>
response.json()Parse body sebagai JSON.
fetch('/api').then(r => r.json())Promise<any>
response.text()Description: Parse body sebagai teks.
Example:
fetch('/api').then(r => r.text())Output: Promise<string>
response.text()Parse body sebagai teks.
fetch('/api').then(r => r.text())Promise<string>
response.statusDescription: HTTP status code.
Example:
response.status
Output: 200
response.statusHTTP status code.
response.status
200
ERROR
Name
Description
Example
Output
try { ... } catch (err) { ... } finally { ... }Description: Tangani error.
Example:
try { throw new Error('fail') } catch(e) { e.message }Output: 'fail'
try { ... } catch (err) { ... } finally { ... }Tangani error.
try { throw new Error('fail') } catch(e) { e.message }'fail'
throw new Error(msg)Description: Lempar error baru.
Example:
throw new Error('something wrong')Output: Error
throw new Error(msg)Lempar error baru.
throw new Error('something wrong')Error