The primary differences between let
and var
are their scoping rules and hoisting behavior:
- Scope:
let
is block-scoped, whilevar
is function-scoped. - Hoisting: Both
let
andvar
are hoisted to the top of their scope, butlet
is not initialized until the code execution reaches it, leading to a Temporal Dead Zone (TDZ).
Tags: basic, let, var, JavaScript
URL: https://www.tiktok.com/@jsmentoring/photo/7446417854699687200