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 Input <T> = string | number | T | |
const i: Input<boolean> = false | |
const x: Input<number[]> = [1, 2, 3] | |
interface Guest { | |
name: string | |
email: string | |
age: number |
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
interface Person { | |
name: string | |
age: number | |
email: string | |
phone: string | |
} | |
interface SpecialPerson extends Person { | |
reason: string | |
} | |
const tallulah: SpecialPerson = { |
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
interface Guest { | |
name: string | |
age: number | |
email: string | |
phone: string | |
address: string | |
} | |
type GuestKey = keyof Guest // 'name' | 'age' | 'email' | 'phone' | 'address' | |
const dorothy = { |
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 review = { message: 'Those were some cute dogs!' } | |
const reviewJson = JSON.stringify(review) | |
localStorage.setItem('review', reviewJson) | |
const localReview = localStorage.getItem('review') | |
console.log('localReview', localReview) | |
console.log('localReview.message', localReview.message) | |
const parsedReview = JSON.parse(localReview) | |
console.log('parsedReview.message', parsedReview.message) | |
</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> | |
async function upload () { | |
const review = { message: 'Those are some cute dogs!' } | |
const reviewJson = JSON.stringify(review) | |
const init = { | |
method: "POST", | |
body: reviewJson | |
} | |
const response = await fetch('https://dog.ceo/api/breeds/image/random', init) | |
const data = response.json() |
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="image" widt="400"/> | |
<script> | |
async function download () { | |
const response = await fetch('https://dog.ceo/api/breeds/image/random') | |
const data = await response.json() | |
console.log('data', data) | |
const image = document.getElementById('image') | |
image.src = data.message | |
} | |
download() |
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> | |
// synchronous (wait) | |
console.log('before') | |
function sleep(ms) { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
resolve() | |
}, ms) | |
}) |
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> |
NewerOlder