JavaScript · Language basics
var
Function-scoped and hoisted. Kept for legacy code; use let or const instead.
Syntax
var x = 1;Example
Try it
Notes
var leaks out of blocks and initialises as undefined before its declaration.
More in this group
Learn this in the course
Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.