Skip to content

Instantly share code, notes, and snippets.

View indreklasn's full-sized avatar
👋

Trevor I. Lasn indreklasn

👋
View GitHub Profile
class CustomDate {
// ...
static epoch = new CustomDate(0);
}
/* or */
class CustomDate {
// ...
}
const x = Number.MAX_SAFE_INTEGER;
// ↪ 9007199254740991, this is 1 less than 2^53
const y = x + 1;
// ↪ 9007199254740992, ok, checks out
const z = x + 2
// ↪ 9007199254740992, wait, that’s the same as above!
const theBiggestInt = 9007199254740991n;
const alsoHuge = BigInt(9007199254740991);
// ↪ 9007199254740991n
const hugeButString = BigInt('9007199254740991');
// ↪ 9007199254740991n
const x = Number.MAX_SAFE_INTEGER;
// ↪ 9007199254740991, this is 1 less than 2^53
const y = x + 1;
// ↪ 9007199254740992, ok, checks out
const z = x + 2
// ↪ 9007199254740992, wait, that’s the same as above!
const response = {
settings: {
nullValue: null,
height: 400,
animationDuration: 0,
headerText: '',
showSplashScreen: false
}
};
// Potentially unintended. '' is falsy, result: 'Hello, world!'
const headerText = response.settings.headerText || 'Hello, world!';
// Potentially unintended. 0 is falsy, result: 300
const animationDuration = response.settings.animationDuration || 300;
// Potentially unintended. false is falsy, result: true
const showSplashScreen = response.settings.showSplashScreen || true;
const response = {
settings: {
nullValue: null,
height: 400,
animationDuration: 0,
headerText: '',
showSplashScreen: false
}
};
obj?.prop // optional static property access
obj?.[expr] // optional dynamic property access
func?.(...args) // optional function or method call
iterator.return?.() // manually close an iterator
data?.map(item => <div>{item}<div>