This file contains 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 foo() { | |
let a = b = 0; | |
a++; | |
return a; | |
} | |
foo(); | |
console.log(typeof a); | |
console.log(typeof b); |
This file contains 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
<script> | |
// Debouncing in Javascript | |
let counter = 0; | |
const getData = () => { | |
// calls an API and gets Data | |
console.log("Fetching Data ..", counter++); | |
} | |
const debounce = function (fn, d) { | |
let timer; |
This file contains 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 song1 = { | |
song: 'Blank Space', | |
getSong: function() { | |
console.log(this.song); | |
} | |
}; | |
let song2 = { | |
song: 'Levitating', | |
}; | |
let song3 = { |
This file contains 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 song1 = { | |
song: 'Blank Space', | |
getSong: function() { | |
console.log(this.song); | |
} | |
}; | |
let song2 = { | |
song: 'Shape of you', | |
}; |
This file contains 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 song = { | |
songName: 'Blank Space', | |
getSong: function() { | |
console.log(this.songName); | |
} | |
}; | |
let song1 = song.getSong.bind(song); // Blank Space | |
setTimeout(song1, 1000); |
This file contains 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 song = { | |
songName: 'Blank Space', | |
getSong: function() { | |
console.log(this.songName); | |
} | |
} | |
let song1 = song.getSong; | |
setTimeout(song1, 1000);// undefined |
This file contains 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 song = { | |
songName: 'Blank Space', | |
getSong: function() { | |
console.log(this.songName); | |
} | |
} | |
setTimeout(song.getSong, 1000)// undefined |
This file contains 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 singerName() { | |
console.log(this.name); | |
} | |
let singer1 = {name: 'Taylor Swift'}; | |
let taylor = singerName.bind(singer1); | |
taylor(); // Taylor Swift |
This file contains 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 singer = { | |
name: "Dua Lipa", | |
songs: function() { | |
function songAndSinger(){ | |
console.log(this === singer) // true | |
} | |
songAndSinger.apply(singer) | |
} | |
} | |
singer.songs(); |
This file contains 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 singer = { | |
name: "Dua Lipa", | |
songs: function() { | |
function songAndSinger() { | |
console.log(this === singer) // true | |
} | |
songAndSinger.call(singer); | |
} | |
} | |
singer.songs(); |
NewerOlder