Skip to main content

BlockSource Code Encapsulate in { } curly braces (excl Object Literals) to define boundary of Lexical Environment

aka Blocks, Code-Block, Code-Blocks, Block-of-code

!recall if & loop statements are inside a block

{ const isPrivate = true }

true. can not read from outside; const block-scoped

{ var notPrivate = true }

true. readable outside Block since var is Function Scoped

References

  1. Global Scope ↔ Outside any Block. Variableaccess everywhere

  2. function ↔ callable Block of code to perform action or return Value

  3. Block ScopeVariable Lookup restrict to inside of Block

  4. { var notPrivate = true } ↔ true. readable outside Block since var is Function Scoped

  5. LoopControl Flow to repeat Block Execution

  6. ifControl Flow JS Keyword to optionally execute Block on Boolean Context of expression

  7. Top-Level CodeCode in Global Scope, outside Block