DEV Community

badruti94
badruti94

Posted on

Catatan belajar "Belajar Dasar Pemrograman Javascript" dari dicoding

  • Menamai variabel "data" itu buruk. Penamaan variabel harus sesuai makna dari variabel itu sendiri
//Ini contoh yang salah
data.forEach(data => {/* */});
//Ini contoh yang benar
articles.forEach(article => {/* */});

Enter fullscreen mode Exit fullscreen mode
  • Trailing coma pada property terakhir dari objek itu membantu. Sebaiknya dilakukan
const article = {
    id: 1,
    title: 'Peran AI dalam Pendidikan',
    slug: 'peran-ai-dalam-pendidikan',
    author: 'Budi S', //ini contoh trailing coma
}
Enter fullscreen mode Exit fullscreen mode
  • Throw error digunakan untuk menciptakan error sendiri. Contohnya variabel undifined, itu tidak dianggap error oleh runtime maka bisa kita buat error dengan menggunakan throw error
throw new Error('variable undifined');
Enter fullscreen mode Exit fullscreen mode
  • Kita bisa membuat Custom Error sendiri dengan membuat class turunan dari class Error
class ValidationError extends Error {
    constructor(message){
        super(message)
        this.name = 'Validation Error'
    }
}
Enter fullscreen mode Exit fullscreen mode
  • Unit testing adalah pengujian pada bagian kecil

  • Integration testing adalah pengujian fungsi yang bergantung pada fungsi lainnya

  • End to end testing adalah pengujian flow dari hulu ke hilir

  • Promise all menjalankan promise secara paralel. Jika salah satu promise reject maka akan me return promise tersebut tanpa promise lain

  • Promise allSettle sama seperti all tapi me return semua promise baik yang resolve maupun failed

  • Asin await sangat dianjurkan karena membuat code lebih enak untuk dibaca. Asin await itu menulis code asynchronous dengan style synchronous

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay