Skip to content

Instantly share code, notes, and snippets.

View omarkdev's full-sized avatar

Marcos Felipe omarkdev

View GitHub Profile
class User {
name: string = 'Marcos';
changePassword(newPassword: string) { }
}
const user = new User();
for (const key in user) {
console.log(key);
function /* Sum two numbers */ sum(a, b) {
return a + b; // Sum a + b
}
sum.toString();
// "function /* Sum two numbers */ sum(a, b) {
// return a + b; // Sum a + b
// }"
try {
throw new Error('Useless Error');
} catch {
console.log('Ignoring the exception');
}
// Ignoring the exception
const symbol1 = Symbol('Awesome');
symbol1.description;
// "Awesome"
const symbol1 = Symbol('Awesome');
symbol1.toString();
// "Symbol(Awesome)"
const message = ' Hello world! ';
message.trimEnd();
// " Hello world!"
message.trimStart();
// "Hello world! "
const entries = [ ['name', 'Marcos'], ['site', 'omark.dev'], ['twitter', '@omarkdev'] ];
Object.fromEntries(entries);
// {name: "Marcos", site: "omark.dev", twitter: "@omarkdev"}
const arr1 = [1, 2, 3, 4];
const arr1FlattedMultipliedByTwo = arr1.flatMap(v => [ v * 2 ]);
// arr1FlattedMultipliedByTwo
const arr1 = ['a', 'b', , , , ['c', , 1, null, undefined, '', 0]];
const arr1Flatted = arr1.flat();
// ["a", "b", "c", 1, null, undefined, "", 0]
const arr1 = ['a', ['b', ['c']], 1, [2, [3, [4, [5]]]]];
const arr1Flatted1 = arr1.flat();
// ["a", "b", Array(1), 1, 2, Array(2)]
const arr1Flatted2 = arr1.flat(2);
// ["a", "b", "c", 1, 2, 3, Array(2)]
const arr1FlattedInfinity = arr1.flat(Infinity);
// ["a", "b", "c", 1, 2, 3, 4, 5]