# स्कोप और Hoisting — JavaScript Fundamentals: Syntax से Async तक

Source: https://www.skillbyai.com/hi/javascript/js-scope-hoisting

> Global, function और block scope, hoisting तथा let व const के temporal dead zone को समझें।

## फ़ंक्शन बनाम ब्लॉक स्कोप

वेरिएबल का scope यह तय करता है कि वह कहाँ दिखता है: `var` घेरने वाले फ़ंक्शन तक सीमित है, जबकि `let`/`const` घेरने वाले `{ }` ब्लॉक तक।

## Hoisting

Compilation के दौरान घोषणाएँ अपने scope के ऊपर ले जाई जाती हैं — पर सिर्फ़ घोषणा, असाइनमेंट नहीं।

```js
console.log(x);   // undefined, not an error
var x = 5;

console.log(y);   // ReferenceError
let y = 5;
```

## टेम्पोरल डेड ज़ोन

`let`/`const` भी hoisted होते हैं, पर अपनी लाइन चलने तक "temporal dead zone" में रहते हैं — पहले एक्सेस करने पर त्रुटि आती है।
