} -->
Jelaskan perbedaan div dan span
Jelaskan perbedaan HTML vs XHTML
Jelaskan perbedaan Element dan Tag HTML
contoh:
<p>Ini adalah elemen</p>
Apa yang dimaksud dengan Semantic HTML
berikut ini gambaran penggunaan semantic HTML:
Apa fungsi dari !DOCTYPE html
Bisakah CSS menggunakan @import?
Ya, digunakan untuk mengimpor file CSS lain ke dalam satu file CSS utama.
👉 Kelebihan: Bisa memisahkan file CSS. 👉 Kekurangan: Meningkatkan waktu load karena CSS dimuat secara async.
Perbedaan CSS padding vs margin
Apa saja Unit baru pada CSS3
contoh svh,lvh,&dvh:
Unit mana yang membantu desain web responsif?
Apa yang dimaksud dengan CSS Specificity?
Selector | Specificity |
---|---|
element (p, div) | 0,0,1 |
class, :pseudo-class (.box, :hover) | 0,1,0 |
id (#container) | 1,0,0 |
Inline styles (style="") | 1000 |
Semakin besar angka specificity, semakin tinggi prioritasnya.
Bagaimana Cara membuat variabel di dalam CSS
:root {
--primary-color: #ff5733;
}
div {
background-color: var(--primary-color);
}
Jelaskan perbedaan dari inline, block, dan inline-block
Apa itu Pseudo-Class dalam CSS?
a:hover {
color: red;
}
input:focus {
border: 2px solid blue;
}
Bagaimana cara membuat sebuah div yang ada di dalam div lain berada di tengah (center)?
.parent {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.parent {
display: grid;
place-items: center;
height: 100vh;
}
Apa itu Grid System di CSS?
Sebutkan apa saja aturan pada CSS Ruleset
Apakah Javascript Async atau sync?
Secara default sync, tapi bisa async dengan setTimeout, Promise, async/await.
- Async: Kode bisa berjalan di latar belakang tanpa menghentikan eksekusi kode lainnya. JavaScript menggunakan callback, promises, dan async/await untuk menangani proses async.
- Sync: Kode dieksekusi secara berurutan, satu per satu. Jika satu operasi memakan waktu lama, maka kode di bawahnya akan menunggu.
Apa perbedaan var, const dan let?
Tipe data pada Js
Apa itu DOM?
contoh manipulasi DOM:
document.getElementById('title').innerText = 'Hello!'
Apa perbedaan antara Array & Object ?
Perbedaan == dan === ?
1 == '1' // true
1 === '1' // false
Apa itu this?
contoh:
const obj = {
name: 'Ubay',
greet: function () {
console.log(this.name)
},
}
obj.greet() // "Ubay"
function getPath() {
return this.location.pathname // sama saja dengan `window.location.pathname`
}
Apa perbedaan dari arrow function dan regular function?
contoh 1. sintaks:
// regular function
function sayHello(name) {
return `Hello, ${name}!`
}
console.log(sayHello('Ubay')) // "Hello, Ubay!"
// arrow function
const sayHello = (name) => `Hello, ${name}!`
console.log(sayHello('Ubay')) // "Hello, Ubay!"
contoh 2. this binding:
// regular function
// this mengacu ke person karena dipanggil dari objek.
const person = {
name: 'Ubay',
sayName: function () {
console.log(this.name)
},
}
person.sayName() // "Ubay"
// arrow function
// Arrow function tidak memiliki this sendiri, sehingga mengambil this dari global scope, bukan person.
const person = {
name: 'Ubay',
sayName: () => {
console.log(this.name)
},
}
person.sayName() // undefined
contoh 3. hoisting
// regular function
sayHello('Ubay') // "Hello, Ubay!"
function sayHello(name) {
console.log(`Hello, ${name}!`)
}
// arrow function
sayHello('Ubay') // ❌ Error: Cannot access 'sayHello' before initialization
const sayHello = (name) => console.log(`Hello, ${name}!`)
contoh 4. arguments
// regular function
function showArgs() {
console.log(arguments)
}
showArgs(1, 2, 3) // [1, 2, 3]
// arrow function
const showArgs = () => {
console.log(arguments)
}
showArgs(1, 2, 3) // ❌ Error: arguments is not defined
// solusinya kita bisa gunakan rest parameter
const showArgs = (...args) => {
console.log(args)
}
showArgs(1, 2, 3) // [1, 2, 3]
contoh 5. constructors
// regular function
function Person(name) {
this.name = name
}
const ubay = new Person('Ubay')
console.log(ubay.name) // "Ubay"
// arrow function
const Person = (name) => {
this.name = name
}
const ubay = new Person('Ubay') // ❌ Error: Person is not a constructor
NOTED:
- Gunakan Arrow Function untuk callback, function expression, dan ketika tidak butuh this.
- Gunakan Regular Function jika butuh hoisting, arguments object, atau menggunakan this dengan cara tradisional.
Apa itu undefined dan null?
Apa perbedaan for, while, dan do while loop?
contoh for loop menampilkan angka 1-5
for (let i = 1; i <= 5; i++) {
console.log(i)
}
contoh while loop, Loop sampai dapat angka random < 0.1
let num = Math.random()
while (num >= 0.1) {
console.log(num)
num = Math.random()
}
console.log('yeay nilai < 0.1 = ', num)
contoh do while loop, Memutar Dadu Sampai Mendapat Angka 6
let dice
// dadu dilempar sekali lalu di cek pada while, jika angka !== 6 maka lakukan lemparan lagi sampai dapat angka 6.
do {
dice = Math.floor(Math.random() * 6) + 1
console.log('Dadu keluar:', dice)
} while (dice !== 6)
console.log('Akhirnya dapat angka 6!')
kenapa do while disebut selalu berjalan minimal satu kali ?
Karena dalam do while, kode di dalam blok {} dijalankan dulu, lalu baru dicek kondisinya.
Bandingkan dengan while, yang mengecek kondisi dulu sebelum menjalankan kode.
perbedaan while & do while
while (cek dulu, baru eksekusi)
let angka = 10 // Karena angka > 10 false sejak awal, kode di dalam {} tidak akan pernah dijalankan. while (angka > 10) { // ❌ Kondisi langsung false console.log('Ini tidak akan pernah muncul!') }
do while (eksekusi dulu, baru cek)
let angka = 10 // Walaupun angka > 10 itu false sejak awal, console.log tetap dijalankan satu kali sebelum dicek. do { console.log('Ini pasti muncul minimal sekali!') } while (angka > 10)
Apa itu closure ?
contoh:
function counter() {
let count = 0 // Variabel di luar inner function
return function () {
count++ // Bisa akses count meskipun di luar scope-nya
console.log(count)
}
}
const increment = counter() // Simpan closure di variabel
increment() // 1
increment() // 2
increment() // 3
function multiplier(factor) {
return function (number) {
return number * factor
}
}
const double = multiplier(2)
const triple = multiplier(3)
console.log(double(5)) // 10
console.log(triple(5)) // 15
Apakah setTimeout async atau sync ?
Apa itu Higher-order Function ?
contoh:
// fn disini sebagai parameter.
// dan fungsi operasi menjadikan fungsi fn sebagai hasil.
function operasi(angka, fn) {
return fn(angka)
}
console.log(operasi(5, (n) => n * 2)) // 10
Apa itu Hoisting ?
Apa itu Callback?
Apa itu Promise?
Ketika membuat sebuah Promise, apa yang akan terjadi jika catch tidak dijalankan?
Apa itu concurrency dan parallelism?
contoh concurrency:
console.log('Mulai')
setTimeout(() => {
console.log('Tugas Async 1 (2 detik)')
}, 2000)
setTimeout(() => {
console.log('Tugas Async 2 (1 detik)')
}, 1000)
console.log('Selesai')
----------------------------------------------
// hasilnya:
// 1. Mulai 🟢
// 2. setTimeout(2s) ⚫ (menunggu)
// 3. setTimeout(1s) ⚫ (menunggu)
// 4. Selesai 🟢
// 5. 1 detik berlalu → Tugas Async 2 selesai 🟢
// 6. 2 detik berlalu → Tugas Async 1 selesai 🟢
ini adalah gambaran bagaimana cara kerja concurrency.
lalu kapan menggunakan paralellism ?
Jangan gunakan Parallelism jika:
Bagaimana Javascript (yang notabene nya single-threaded) menangani proses asynchronous?
Implementasi Oberserver Pattern dengan dengan menampilkan inputan user dari field input
📌 Cocok untuk:
contoh dari pertanyaan:
// Class Subject (Publisher)
class InputSubject {
constructor() {
this.observers = []
}
subscribe(observer) {
this.observers.push(observer)
}
notify(value) {
this.observers.forEach((observer) => observer(value))
}
}
// Buat Subject
const inputSubject = new InputSubject()
// Observer 1 (Menampilkan teks di div)
const displayText = (text) => {
document.getElementById('output1').innerText = text
}
// Observer 2 (Menampilkan teks di console)
const logText = (text) => {
console.log('User mengetik:', text)
}
// Subscribe kedua observer
inputSubject.subscribe(displayText)
inputSubject.subscribe(logText)
// Event Listener pada input field
document.getElementById('userInput').addEventListener('input', (e) => {
inputSubject.notify(e.target.value)
})
<input type="text" id="userInput" placeholder="Ketik sesuatu..." />
<p>Output: <span id="output1"></span></p>
penjelasan:
Saat user mengetik di form input, event notify(value) akan dijalankan.
Semua observer yang terdaftar (console log dan span output) akan menerima perubahan input.