Skip to content

Instantly share code, notes, and snippets.

@hemkaran
Created July 21, 2019 14:37
Show Gist options
  • Save hemkaran/164052f41e34f4357e02f02d43483767 to your computer and use it in GitHub Desktop.
Save hemkaran/164052f41e34f4357e02f02d43483767 to your computer and use it in GitHub Desktop.
React Meetup Talk: I don't know that
function main() {
return Array.from(
'Hello World', // Array like object OR iterable (arguments, Map, Set, String)
ch => ch + 'c'
);
}
console.log(main()); //
function main() {
return /a\nc/s.test('a#c');
}
console.log(main()); //
// It's very new (ES2018), check for compatibility
function main() {
try {
throw Error('Error in try');
return 'Try Me!!';
} catch (e) {
return 'Catch Me!!';
} finally {
console.log('here');
//return 'finally';
}
}
console.log(main()); //
// Finally is always right (just like a girl :D)
function main() {
return JSON.stringify(
{
foo: 'bar',
// hello: {
// a: 2,
// },
//bar: undefined,
//bar: [10, undefined]
//bar: function () { console.log() },
//bar: [10, function() { console.log()}],
//bar: Symbol('bar'),
bar: [10, Symbol('bar')],
},
null,
2
);
}
console.log(main());
function main() {
return JSON.stringify(
{
foo: 'bar',
bar: [10, undefined],
toJSON () { // you can use this to hide sensitive information
return 'blah blah';
}
},
null,
2
);
}
console.log(main()); //
const obj = {
'1': 'integer: 2',
'foo': 'string: foo',
'01': 'string: 01',
011: 'string: 01',
1: 'integer: 1',
[Symbol('first')]: 'symbol: first'
};
obj['0'] = '0';
obj[Symbol('last')] = 'symbol: last';
obj['veryLast'] = 'string: very last';
console.log(Reflect.ownKeys(obj));
console.log(Object.keys(obj));
function main() {
try {
throw Error('Oh my God');
} catch {
return 'Some Error';
}
}
console.log(main()); //
Promise.resolve('Hello').then(
value => {
console.log(`Resolution with: ${value}`) //
}
);
Promise.resolve(
{ then: 42 }
).then(
value => {
console.log(`Resolution with: ${JSON.stringify(value)}`); //
}
);
Promise.resolve({
then: (...args) => {
console.log(args); //
//args[0]('some value')
}
}).then(
// This will not be logged
value => {
console.log(`Resolution with: ${value}`) //
}
);
function compare() {
return [
'aBcD' === 'abcd',
'åbcd' === 'abcd',
]
}
console.log(compare()); //
function compare() {
return [
'aBcD'.localeCompare('abcd', undefined, { sensitivity: 'base'}),
'åbcd'.localeCompare('abcd', undefined, { sensitivity: 'base'}),
]
}
console.log(compare()); //
// Note: This is a very slow function, so use carefully.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment