Javascript variables: Difference between revisions

From wikinotes
(No difference)

Revision as of 19:52, 23 May 2021

Variable Scope

execute-context-scoped:  # variable scoped to function, or module if not defined in function
block-scoped:            # variable scoped to the { ... } contents

Declaration & Assignment

var foo          // declare var (execute-context-scoped)
let foo          // declare var (block-scoped)
const foo        // declare constant (read-only) (block scoped)

var foo = "bar"  // declare/assign variable (execute context scoped)
let foo = "bar"  // declare/assign variable (block scoped)