---
title: 'Does Your Code Suck? JavaScript Variables Edition'
source: 'https://youtube.com/watch?v=ZRjmGq1gAEQ'
video_id: 'ZRjmGq1gAEQ'
date: 2026-07-14
duration_sec: 0
---

# Does Your Code Suck? JavaScript Variables Edition

> Source: [Does Your Code Suck? JavaScript Variables Edition](https://youtube.com/watch?v=ZRjmGq1gAEQ)

## Summary

This video explains why using 'var' in JavaScript can lead to confusing bugs due to hoisting, and how 'let' provides a clearer, safer alternative by enforcing the temporal dead zone.

### Key Points

- **The Problem with var** [00:00] — Variables declared with var are hoisted to the top of their scope, but only the declaration is hoisted, not the assignment. This causes undefined to be logged instead of throwing an error, making debugging difficult in large codebases.
- **How let Solves It** [00:00] — Variables declared with let are also hoisted but cannot be accessed before declaration due to the temporal dead zone. This results in a clear ReferenceError, making bugs easier to identify and fix.

### Conclusion

Using 'let' instead of 'var' helps avoid subtle bugs caused by hoisting, leading to more predictable and maintainable JavaScript code.

## Transcript

let's play does your code suck JavaScript variables Edition one of these code examples does something annoyingly weird can you tell which [Music] one nope you're wrong it's the bottom one the code with VAR doesn't throw an error but that's actually why it sucks variables with VAR get hoisted to the top of their scope by the JavaScript engine however only the Declaration is hoisted not the value assigned to it which means this confusingly logs out undefined in a large code base that can be a nightmare to debug let on the other hand can only be accessed after the Declaration everything above it is called the temporal dead zone so what we get is a nice clear error that can be easily debugged
