This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var city = 'Karur'; | |
console.log(this.city); // Karur | |
console.log(city); //Karur |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (exports, require, module, __filename, __dirname) { | |
//****Your code starts here****// | |
var city = 'Karur'; | |
console.log(this.city); // undefined | |
console.log(city); //Karur | |
//****Your code ends here****// | |
}); | |
var args = [self.exports, require, self, filename, dirname]; | |
return compiledWrapper.apply(self.exports, args); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var slang = 'Kongu'; | |
function printSlang() { | |
console.log(this.slang); // Kongu | |
} | |
printSlang(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run it in Browser | |
function thisInBrowser() { | |
console.log(this === window); // true | |
} | |
thisInBrowser(); | |
//Run it in Node.js | |
function thisInNodeJS() { | |
console.log(this === global); // true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let manchesterOfSouthIndia = { | |
city: 'Coimbatore', | |
speciality: 'cotton industries', | |
getSpeciality: function() { | |
return this.city + ' is known for ' + this.speciality; | |
} | |
} | |
console.log(manchesterOfSouthIndia.getSpeciality()); // Coimbatore is known for cotton industries |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let manchesterOfSouthIndia = { | |
city: 'Coimbatore', | |
speciality: 'mechanical industries', | |
} | |
manchesterOfSouthIndia.getSpeciality = function() { | |
return this.city + ' is known for ' + this.speciality; | |
} | |
console.log(manchesterOfSouthIndia.getSpeciality()); // Coimbatore is known for mechanical industries |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const siliconVallyOfIndia = { | |
city: 'Bengaluru', | |
speciality: 'software industries' | |
}; | |
const texCity = { | |
city: 'Tiruppur', | |
speciality: 'textile industries' | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function printSpeciality() { | |
console.log(`${this.city} is know for ${this.speciality}`); | |
} | |
const printKarurSpeciality = printSpeciality.bind({city: 'Karur', speciality: 'Textile Industries'}); | |
printKarurSpeciality(); // Karur is know for Textile Industries | |
const printCoimbatoreSpeciality = printSpeciality.bind({city: 'Coimbatore', speciality: 'Mechanical Industries'}); | |
printCoimbatoreSpeciality(); // Coimbatore is know for Mechanical Industries |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<button id="thisButton">Check this</button> | |
<script> | |
const thisButton = document.getElementById('thisButton'); | |
thisButton.addEventListener('click', verifyThis); | |
function verifyThis(event) { | |
//this is bound to the button onwhich the click event is triggered | |
console.log(this === thisButton); // true | |
console.log(this === event.currentTarget); // true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<button id="thisButton" onclick="verifyThis(this)">Check this</button> | |
<script> | |
const thisButton = document.getElementById('thisButton'); | |
function verifyThis(buttonWhichTriggered) { | |
console.log(buttonWhichTriggered === thisButton); // true | |
console.log(this === window); // true | |
} | |
</script> |
OlderNewer