show dbs
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 id: number = 5; | |
let company: string = "Eric"; | |
let isBool: boolean = true; | |
let x: any = 2; | |
x = false; | |
let ids: number[] = [1, 2, 3, 4, 5]; | |
let arr: any[] = [1, true, "asf"]; | |
// Tuple (fixed number of elements and types) |
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
// PATTERN | |
// MODULE PATTERN | |
// BASIC Structure | |
// IIFE (immediate invoked function expression) | |
(function () { | |
// Declare private vars and functions | |
return { |
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
// SET - unique values | |
const set1 = new Set(); | |
set1.add(100); | |
set1.add('A string'); | |
set1.add({ name: 'John' }); | |
set1.add(true); | |
set1.add(100); |
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
// MAP (key-value pair) | |
const map = new Map(); | |
const key1 = 'string key', | |
key2 = {}, | |
key3 = function () {}; | |
map.set(key1, 'value of key1'); | |
map.set(key2, 'value of key2'); | |
map.set(key3, 'value of key3'); |
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
// Destructuring Assignment | |
let a, b; | |
[a, b] = [100, 200]; | |
// Basic + (rest) | |
[a, b, c, ...rest] = [100, 200, 300, 400, 500]; | |
// # OBJECT # + (rest) | |
({ a, b, ...rest } = { a: 100, b: 200, c: 300, d: 400, e: 500 }); |
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 data = [ | |
{ | |
name: 'John Doe', | |
age: 32, | |
gender: 'male', | |
lookingfor: 'female', | |
location: 'Boston MA', | |
image: 'https://randomuser.me/api/portraits/men/82.jpg' | |
}, | |
{ |
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
// Iterator | |
function nameIterator(names) { | |
let nextIndex = 0; | |
return { | |
next: function () { | |
return nextIndex < names.length | |
? { value: names[nextIndex++], done: false } | |
: { done: 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
let reg, result, str; | |
reg = /hello/g; // global search | |
reg = /hello/; | |
reg = /hello/i; // i == flag : case insensitive | |
console.log(reg); | |
console.log(reg.source); | |
// exec() - result in array or null | |
result = reg.exec('hello world'); |
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 = { email: '[email protected]' }; | |
try { | |
if (!user.name) { | |
// throw 'User has no name'; | |
throw new SyntaxError('User has no name'); | |
} | |
} catch (e) { | |
console.log(`User Error: ${e.message}`); | |
// console.log(e.message); |
NewerOlder