# var

An older keyword for declaring a variable that belongs to the whole function, not just the block it's in.

## 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
}
```

Level: Novice · [More JavaScript terms at this level](https://www.ask-codey.com/glossary/subjects/javascript/novice)

Updated: October 19, 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
