Javascript
JavaScript Fundamentals -- Variables and Scope

Block Scope

Variables declared with block scope:

  • Are declared using let and const
  • Are usable in the block where they're declared
  • A block is anywhere encompassed with {}
  • Cause a ReferenceError if used before declaration

Block scope is my personal preference. This way I can't accidentally use variables before they've been declared, and it is one less place that I can have a bug in my code.

For more information on this topic, check out this blog post.