यदि बलों की घोषणा का दायरा है। इसे एक फ़ंक्शन में डालकर आप यह सुनिश्चित कर रहे हैं कि आपके द्वारा बनाए गए चर और कॉल को फिर से घोषित नहीं किया जा रहा है या आप गलती से चर को कॉल नहीं कर रहे हैं जिन्हें कहीं और घोषित किया गया है।
http://javascript.crockford.com/code.html
नीचे टिप्पणी पर पालन करने के लिए:
तो .....
var variable = 5; // this is accessible to everything in the page where:
function()
{
var variable = 7 // this is only available to code inside the function.
}
यहाँ जावास्क्रिप्ट में गुंजाइश के बारे में बात डगलस Crockford की साइट के लिए लिंक है
जावास्क्रिप्ट का दायरा थोड़ा "टूटा हुआ" है:
function()
{
var x = 3; // accessible in the entire function.
//for scope reasons, it's better to put var y = 8 here.....
if(x != 4)
{
var y = 8; //still accessible in the entire function.
//In other languages this wouldn't be accessible outside
//of the if statement, but in JavaScript it is.
}
}
बहुत यकीन है कि यह एक डुप्लिकेट है .... –