JavaScript This कीवर्ड उस ऑब्जेक्ट को संदर्भित करता है जिससे यह संबंधित होता है। यह अकेले या फंक्शन के अंदर ग्लोबल ऑब्जेक्ट को संदर्भित कर सकता है। यह मेथड के अंदर ओनर ऑब्जेक्ट को संदर्भित करता है और इवेंट लिसनर में उस HTML एलिमेंट को संदर्भित करता है जिसने इवेंट प्राप्त किया।
उदाहरण
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { font-size: 18px; font-weight: 500; color: red; } </style> </head> <body> <h1>JavaScript this Identifier</h1> <div class="sample"></div> <div class="result"></div> <button class="Btn">CLICK HERE</button> <h3> Click on the above button to see which object 'this' refers to in multiple context </h3> <script> let thisRef = this; let sampleEle = document.querySelector(".sample"); function test() { return this; } let testObj = { a: 22, check() { return this; }, }; document.querySelector(".Btn").addEventListener( "click", () => { sampleEle.innerHTML ="This inside normal function = " + test() + "<br>"; sampleEle.innerHTML +="This inside a method = " + testObj.check() + "<br>"; sampleEle.innerHTML += "This without any scope = " + thisRef + "<br>"; }, false ); </script> </body> </html>आउटपुट

"CLICK HERE" बटन पर क्लिक करने पर -
