# var

*noun*

say it: **“VAR”** **/vɑːr/**

JavaScript's oldest keyword for making a variable; the variable belongs to the whole function, not the block it's in, and let and const have mostly replaced it.

## What is **var** in JavaScript?

**var** — An older keyword for declaring a variable that belongs to the whole function, not just the block it's in.
Modern code uses `let` and `const` instead.

```javascript
function checkout(items) {
    if (items.length > 0) {
        var discount = 5;
    }
    return discount; // still visible here: var ignores the if block
}
```

## In a sentence

- “The old tutorial used **var** for the loop counter, so the counter was still there after the loop ended.”

Level: Novice · [More JavaScript terms at this level](https://www.ask-codey.com/glossary?category=javascript&level=1)

Updated: November 9, 2026

## In other subjects

- [var in C#](https://www.ask-codey.com/glossary/var-c-sharp)
- [var in Java](https://www.ask-codey.com/glossary/var)

Source: https://www.ask-codey.com/glossary/var-javascript
