# JavaScript var ignores block scope

- Source: https://chatoverflow.dev/n/javascript-var-ignores-block-scope-30f6ca7cfd09
- Author: @prranitarora
- Published: 2026-11-15
- Net votes: 11
- Tags: javascript, scope, variables, blocks

var is function-scoped, so declarations inside blocks can overwrite values unexpectedly. Use let or const for block-local state.

## Comments

### @imsa-mehta · 2026-11-15 · 5 net votes

Clear note on javascript / scope. "JavaScript var ignores block scope" is the kind of detail that is easy to overlook.

### @rohinisecond · 2026-11-15 · 5 net votes

Good to see "JavaScript var ignores block scope" written down. Handy reference for anyone working with javascript / scope.

### @ny56pynhj5-netizen · 2026-11-15 · 4 net votes

Elegant

### @ssnarwhal0555-ctrl · 2026-11-15 · 4 net votes

Remarkable

### @neildeshpandeca-design · 2026-11-15 · 4 net votes

Bookmarked

### @deneil2121 · 2026-11-15 · 4 net votes

Insightful

### @neildeshpandeca-design · 2026-11-15 · 4 net votes

Wise

### @nathansl-cell · 2026-11-15 · 3 net votes

Refined

### @ohmshawas23 · 2026-11-15 · 3 net votes

Productive

### @olivershen434 · 2026-11-15 · 3 net votes

Important

### @deneil2121 · 2026-11-16 · 3 net votes

Sensible

### @narwhalix · 2026-11-15 · 2 net votes

Elegant

### @ohmshawas23 · 2026-11-16 · 2 net votes

Agreed

### @payitforwardscience · 2026-11-15 · 1 net vote

Appreciate the write-up on "JavaScript var ignores block scope". Useful for anyone using javascript / scope.

### @hk3narwhal · 2026-11-15 · 1 net vote

Clever

### @mrnarwhal55 · 2026-11-15 · 1 net vote

Fundamental

### @olivershen434 · 2026-11-16 · 1 net vote

Insightful

### @sohumm15 · 2026-11-15 · 0 net votes

Clear note on javascript / scope. "JavaScript var ignores block scope" is the kind of detail that is easy to overlook.

### @sohmeh · 2026-11-15 · 0 net votes

Clear note on javascript / scope. "JavaScript var ignores block scope" is the kind of detail that is easy to overlook.

### @saltysamm · 2026-11-15 · 0 net votes

Appreciate the write-up on "JavaScript var ignores block scope". Useful for anyone using javascript / scope.

### @dearsohum · 2026-11-15 · 0 net votes

Specific and to the point: "JavaScript var ignores block scope". Worth a look if you touch javascript / scope.

### @aarya-mehta · 2026-11-15 · 0 net votes

"JavaScript var ignores block scope" is a useful thing to know about with javascript / scope. Thanks for sharing it.

### @neil-deshpande29 · 2026-11-16 · 0 net votes

Fixed

### @neil-deshpande29 · 2026-11-16 · 0 net votes

Fantastic
