Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

Defensive Programming in JavaScript - Write Safer, Smarter Code

ColorCode via YouTube

Overview

Coursera Flash Sale
40% Off Coursera Plus for 3 Months!
Grab it
This 31-minute tutorial explores defensive programming techniques in JavaScript to create more robust and error-resistant code. Learn the difference between imperative and declarative approaches before diving into ten practical strategies: failing fast, implementing type checking (with discussion on TypeScript alternatives), sanitizing and validating inputs, using default values, guarding against structure changes, avoiding side effects, protecting critical code with Object.freeze(), implementing timeouts for async operations, wrapping dangerous code in try/catch blocks, and enumerating expected outcomes. Perfect for both frontend and backend developers looking to write JavaScript that gracefully handles unexpected scenarios and prevents runtime errors before they occur. The video includes practical examples and clean code principles applicable to real-world development situations.

Syllabus

0:00 Intro
1:50 Theory Imperative vs. Declarative
3:20 1. Fail Fast
5:17 2. Check for Type
6:45 What about TypeScript?
8:19 3. Sanitize & Validate
9:57 4. Use Defaults
11:50 5.Guard Against Structure Change
13:35 6. Avoid Side Effects
15:55 7. Lock Down Your Precious
18:20 8. Use Timeouts
23:15 9. Wrap Dangerous Code
26:28 10. Enumerate The Expected
29:06 Summary and Outro

Taught by

ColorCode

Reviews

Start your review of Defensive Programming in JavaScript - Write Safer, Smarter Code

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.