JavaScript Spread syntax In Hindi : Spread Operator In JavaScript
Set In JavaScript In Hindi | JavaScript Set
JavaScript eval() Function In Hindi | JS eval() Function
Optional chaining in JavaScript In Hindi | JS Optional chaining In Hindi
Syntax Error In JavaScript In Hindi | JS SyntaxError
Linux uname command Example | Linux get OS Info
हैकिंग क्या है ? हैकिंग कितने प्रकार की होती है।
Best Branded Mouse Under 500 In India Available On Amazon
If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
जब भी JavaScript code run होता है तो एक execution context create हो जाता है जो define किये गए Function और Variables के लिए memory allocate करने में help करता है और जिससे पता चलता है कि currently कौन सा code run हो रहा है।
एक Execution Context के अंदर functions और variable declarations के लिए memory allocate करने की mechanism को ही Hoisting कहा जाता है।
javascript में variable hoisting को सिर्फ var keyword के through define किये गए variables ही करते हैं।
For Example
console.log(x);
var x = 65;
console.log(x);
undefined 65
So , example के according normally hoisting का मतलब है define करने से पहले variables या functions को use करना।
अब obviously variable को define करने से पहले use करोगे तो actual value की जगह आपको undefined
मिलेगा , जैसा कि example का output भी है।
आगे बढ़ने से पहले हम ये समझ लेते हैं , कि JavaScript hoisting manage करने के लिए execution context को कैसे create करता है।
basically , Execution context को दो phases में divide किया गया है -
Memory Allocation : इस phase में variables और functions को memory allocate होती है।
execution phase : जबकि execution phase में normally hoisted variables को एक initial value undefined
assign की जाती है , जब तक वो variable को actual value assign नहीं होती है।
JavaScript में आप Functions declarations भी hoisted होता है , मतलब declaration से पहले function को call कर सकते हैं।
For Example
sayHi();
function sayHi(){
console.log("Hi !");
}
Hi !
यहां function , memory allocation phase store हो रहा है , जिसकी वजह से हम उस function को declaration से पहले ही call कर सकते हैं।
ध्यान रहे function hoisting , normal functions पर ही work करती है , Variable Function या Arrow Function पर hoisting apply नहीं होती है।
Example
// Arrow Function.
sayHi();
var sayHi = () => console.log("Hi !");
Uncaught TypeError: sayHi is not a function
// Anonymous/Variable Function.
sayHi();
var sayHi = function(){
console.log("Hi !");
}
Uncaught TypeError: sayHi is not a function
temporal dead zone (TDZ) एक block of area होता है , जिसमे कोई भी variable तब तक accessible नहीं होता जब तक computer उस variable को completely initialize नहीं करता।
इसीलिए JavaScript में let और const keyword की help से define किये गए सभी variables को declare किये बिना use नहीं किया जा सकता है , या आप कह सकते हैं ये hoisting को support नहीं करते।
For Example
console.log(x); // Start of Temporal dead zone.
let x = 10; // end of temporal dead zone
Uncaught ReferenceError: can't access lexical declaration 'x' before initialization
Loading ...
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook