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
const user = { | |
firstName: 'John', | |
lastName: 'Doe', | |
address: { | |
street: '123 Anywhere Lane', | |
city: 'Some Town', | |
state: 'NY', | |
zip: 12345, | |
}, | |
} |
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
const biggestNumber = Number.MAX_SAFE_INTEGER // 9007199254740991 | |
const incorrectLargerNumber = biggestNumber + 10 | |
// should be: 9007199254741001 | |
// actually stored as: 9007199254741000 |
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
const biggestNumber = BigInt(Number.MAX_SAFE_INTEGER) // 9007199254740991n | |
const correctLargerNumber = biggestNumber + 10n | |
// should be: 9007199254741001n | |
// actually stored as: 9007199254741001n |
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
const useCoolFeature1 = true | |
const useCoolFeature2 = false | |
const useCoolFeature3 = undefined | |
const useCoolFeature4 = null | |
const getUserFeaturePreference = (featurePreference) => { | |
return featurePreference ?? true | |
} | |
getUserFeaturePreference(useCoolFeature1) // true |
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
import { exportPdf } from './pdf-download.js' | |
const exportPdfButton = document.querySelector('.exportPdfButton') | |
exportPdfButton.addEventListener('click', exportPdf) | |
// this code is short, but the 'pdf-download.js' module is loaded on page load rather than when the button is clicked |
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
const exportPdfButton = document.querySelector('.exportPdfButton') | |
exportPdfButton.addEventListener('click', () => { | |
import('./pdf-download.js') | |
.then(module => { | |
// call some exported method in the module | |
module.exportPdf() | |
}) | |
.catch(err => { | |
// handle the error if the module fails to load |
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
// promises 1-3 all will be resolved | |
const promise1 = new Promise((resolve, reject) => setTimeout(() => resolve('promise 1 resolved!'), 100)) | |
const promise2 = new Promise((resolve, reject) => setTimeout(() => resolve('promise 2 resolved!'), 200)) | |
const promise3 = new Promise((resolve, reject) => setTimeout(() => resolve('promise 3 resolved!'), 300)) | |
// promise 4 and 6 will be resolved, but promise 5 will be rejected | |
const promise4 = new Promise((resolve, reject) => setTimeout(() => resolve('promise 4 resolved!'), 1100)) | |
const promise5 = new Promise((resolve, reject) => setTimeout(() => reject('promise 5 rejected!'), 1200)) | |
const promise6 = new Promise((resolve, reject) => setTimeout(() => resolve('promise 6 resolved!'), 1300)) |
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
// promises 1-3 all will be resolved | |
const promise1 = new Promise((resolve, reject) => setTimeout(() => resolve('promise 1 resolved!'), 100)) | |
const promise2 = new Promise((resolve, reject) => setTimeout(() => resolve('promise 2 resolved!'), 200)) | |
const promise3 = new Promise((resolve, reject) => setTimeout(() => resolve('promise 3 resolved!'), 300)) | |
// promise 4 and 6 will be resolved, but promise 5 will be rejected | |
const promise4 = new Promise((resolve, reject) => setTimeout(() => resolve('promise 4 resolved!'), 1100)) | |
const promise5 = new Promise((resolve, reject) => setTimeout(() => reject('promise 5 rejected!'), 1200)) | |
const promise6 = new Promise((resolve, reject) => setTimeout(() => resolve('promise 6 resolved!'), 1300)) |
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
const regexp = /t(e)(st(\d?))/ | |
const regexpWithGlobalFlag = /t(e)(st(\d?))/g | |
const str = 'test1test2' | |
// Using `RegExp.prototype.exec()` | |
const matchFromExec = regexp.exec(str) | |
console.log(matchFromExec) | |
// ["test1", "e", "st1", "1", index: 0, input: "test1test2", groups: undefined] | |
// Using `String.prototype.match()` on a regular expression WITHOUT a global flag returns the capture groups |
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
appState.doesPreferKilograms = JSON.parse(doesPreferKilograms ?? 'true') |
OlderNewer