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
// Type definition for wand using tuple | |
type Wand = [core: string, length: number, material: string] | |
// Enum for house names | |
enum House { | |
Gryffindor = 'Gryffindor', | |
Slytherin = 'Slytherin' | |
} | |
// Type for character |
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
type Message = number | true | 'goodbye' | |
const message1 = 100 | |
const message2 = true | |
const message3 = 'goodbye' | |
const response: Message[] = [true, 'goodbye', true, 100, 42] | |
const firstResponse = response[0] |
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
<script> | |
const localCounter = sessionStorage.getItem('counter') | |
console.log('savedCounter:', localCounter) | |
console.log('typeof savedCounter:', typeof localCounter) | |
const counter = Number(localCounter) | |
const newCounter = counter + 1 | |
const newCounterString = String(newCounter) | |
sessionStorage.setItem('counter', newCounterString) | |
</script> |
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
<script> | |
const localCounter = localStorage.getItem('counter') | |
console.log('savedCounter:', localCounter) | |
console.log('typeof savedCounter:', typeof localCounter) | |
const counter = Number(localCounter) | |
const newCounter = counter + 1 | |
const newCounterString = String(newCounter) | |
localStorage.setItem('counter', newCounterString) | |
</script> |
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
<script> | |
console.log('before') | |
async function main () { | |
const uploadData = { message: 'ready' } | |
const uploadJson = JSON.stringify(uploadData) | |
const init = { body: uploadJson, method: 'POST' } | |
// { body: JSON.stringify(uploadData), method: 'POST' } | |
const dogResponse = await fetch('https://dog.ceo/api/breeds/image/random', init) | |
} | |
main() // asynchronous / non-blocking |
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
<img id="dog" width="500"/> | |
<script> | |
console.log('before') | |
async function main () { | |
console.log('starting dog download...') | |
const dogResponse = await fetch('https://dog.ceo/api/breeds/image/random') | |
const dogData = await dogResponse.json() | |
console.log('dogData', dogData) |
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
<script> | |
// First log 'start' | |
// Then log "starting alpha" | |
// Then, sleep for 2 seconds | |
// Then, log 'alpha' | |
// Then, log "starting beta" | |
// Then, 4 seconds later, log beta | |
// Then, log "starting gamma" | |
// Then, 1 second later log gamma | |
// Then, log "starting delta" |
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
<script> | |
// First log 'start' | |
// Then log "starting alpha" | |
// Then, sleep for 2 seconds | |
// Then, log 'alpha' | |
// Then, log "starting beta" | |
// Then, 4 seconds later, log beta | |
// Then, log "starting gamma" | |
// Then, 1 second later log gamma | |
// Then, log "starting delta" |
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
<script> | |
// First log 'start' | |
// Then log "starting alpha" | |
// Then, 2 seconds later, log alpha | |
// Then, log "starting "beta" | |
// Then, 4 seconds later, log beta | |
// Then, log "starting gamma" | |
// Then, 1 second later log gamma | |
// Then, log "starting delta" | |
// Then, 3 seconds later log delta |
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 x = 'hello!!!' | |
console.log(x) | |
const y = 42 | |
type List = [first: string, second: string, third: number] | |
const list: List = ['a', 'b', 3] | |
function describe <T> (value?: T) { | |
console.log('The value is:', value) |
NewerOlder