language

var

The 'var' keyword is a variable declaration statement in JavaScript used to define variables with function or global scope, introduced in the language's early versions. It allows developers to create variables that can be reassigned and are hoisted to the top of their scope during compilation, but it lacks block-level scoping which can lead to unintended behavior in modern code.

Also known as: var keyword, variable var, var declaration, var statement, var variable
🧊Why learn var?

Developers should learn 'var' primarily for maintaining or understanding legacy JavaScript codebases, as it was the standard before ES6 (2015). It's still used in older scripts, tutorials, or environments that don't support modern JavaScript features, but for new projects, alternatives like 'let' and 'const' are recommended due to their block scoping and better error prevention.

Compare var

Learning Resources

Related Tools

Alternatives to var