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 element = document.getElementById('button'); | |
function onClick(event) { | |
element.innerHtml = 'text'; | |
} | |
element.addEventListener('click', onClick); | |
// Do stuff | |
// ... | |
// Remove handlers |
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 data = getData(); | |
setInterval(function() { | |
const node = document.getElementById('id'); | |
if(node) { | |
// Do stuff with node and data. | |
node.innerHTML = JSON.stringify(data)); | |
} | |
}, 1000); |
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 original = null; | |
const duplicate = function () { | |
const isOriginal = original; | |
const unused = function () { | |
if (isOriginal) { | |
console.log("I'm unused"); | |
} | |
}; |
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 outer() { | |
const obj = { | |
id: 1, | |
name: "David", | |
}; | |
function closure() { | |
const { name } = obj; | |
sayHello(name); | |
} | |
} |
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
// This will also become a global variable as arrow functions | |
// do not have a contextual `this` and instead use a lexical `this` | |
const hey = () => { | |
this.foo = "Hello world!"; | |
} |
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
// This will also become a global variable as global functions have | |
// global `this` as the contextual `this` in non-strict mode | |
function hey() { | |
this.foo = "Hello world!"; | |
} |
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
// This will be hoisted as a global variable | |
function hey() { | |
foo = "Hello world!"; | |
} |
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
fucntion Person(name, dob) { | |
this.name = name; | |
this.dob = dob; | |
} | |
const sherlock = new Person({ | |
name: 'Sherlock Holmes', | |
dob: '01-06-1852'; | |
}); |
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
fucntion Person(name, dob) { | |
this.name = name; | |
this.dob = dob; | |
} | |
const john = new Person({ | |
name: 'Dr John Dollar', | |
dob: '01-08-1866' | |
}); |
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
import useSWR from 'swr'; | |
const Post = () => { | |
const { data, error } = useSWR('/api/post/123', fetch); | |
if (error) { | |
return <div>Error loading post!</div>; | |
} | |
if (!data) { |
NewerOlder