Skip to content

Instantly share code, notes, and snippets.

View zeptobook's full-sized avatar

ZeptoBook zeptobook

View GitHub Profile
class Person {
static age = 25;
static firstname = 'fname';
static lname = 'lname';
static city = 'jersey city';
}
console.log(Person.age);
console.log(Person.firstname);
console.log(Person.lname);
const p1 = new Promise((res, rej) => setTimeout(res, 1000));
const p2 = new Promise((res, rej) => setTimeout(rej, 1000));
Promise.allSettled([p1, p2]).then(data => console.log(data));
// [
// Object { status: "fulfilled", value: undefined},
// Object { status: "rejected", reason: undefined}
// ]
class Message {
#message = "ZeptoBook"
greet() { console.log(this.#message) }
}
const greeting = new Message()
greeting.greet() // ZeptoBook
console.log(greeting.#message) // Private name #message is not defined
if(condition) {
const mathModule = await import('./dynamicModule.js');
mathModule.sum(10, 20);
}
const bigInt = 1234567890123456789012345678901234567890n;
const bigIntFromNumber = BigInt(10); // same as 10n
const nullValue = null;
const emptyText = ""; // falsy
const someNumber = 42;
const valA = nullValue ?? "default for A";
const valB = emptyText ?? "default for B";
const valC = someNumber ?? 0;
console.log(valA); // "default for A"
console.log(valB); // "" (as the empty string is not null or undefined)
const foo = null ?? 'default string';
console.log(foo);
// expected output: "default string"
const baz = 0 ?? 42;
console.log(baz);
// expected output: 0
let func = () => {
return 'function call'
}
console.log(func()) // function call
func = null
console.log(func()) // error: Uncaught TypeError: func is not a function
person = null;
console.log(person?.[0]); // undefined
// or
person = ['adam', 'robert'];
console.log(person?.[2]); // undefined
person = null;
console.log(person[0]); // error: Uncaught TypeError: Cannot read property '0' of null
// or
person = ['adam', 'robert'];
console.log(person[2]); // error: Uncaught TypeError: Cannot read property '0' of null