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
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); |
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 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} | |
// ] |
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
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 |
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
if(condition) { | |
const mathModule = await import('./dynamicModule.js'); | |
mathModule.sum(10, 20); | |
} |
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 bigInt = 1234567890123456789012345678901234567890n; | |
const bigIntFromNumber = BigInt(10); // same as 10n |
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 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) |
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 foo = null ?? 'default string'; | |
console.log(foo); | |
// expected output: "default string" | |
const baz = 0 ?? 42; | |
console.log(baz); | |
// expected output: 0 |
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
let func = () => { | |
return 'function call' | |
} | |
console.log(func()) // function call | |
func = null | |
console.log(func()) // error: Uncaught TypeError: func is not a function |
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
person = null; | |
console.log(person?.[0]); // undefined | |
// or | |
person = ['adam', 'robert']; | |
console.log(person?.[2]); // undefined |
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
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 |
NewerOlder