Created
July 21, 2019 14:37
-
-
Save hemkaran/164052f41e34f4357e02f02d43483767 to your computer and use it in GitHub Desktop.
React Meetup Talk: I don't know that
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
function main() { | |
return Array.from( | |
'Hello World', // Array like object OR iterable (arguments, Map, Set, String) | |
ch => ch + 'c' | |
); | |
} | |
console.log(main()); // |
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
function main() { | |
return /a\nc/s.test('a#c'); | |
} | |
console.log(main()); // | |
// It's very new (ES2018), check for compatibility |
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
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) |
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
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()); |
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
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()); // |
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 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)); |
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
function main() { | |
try { | |
throw Error('Oh my God'); | |
} catch { | |
return 'Some Error'; | |
} | |
} | |
console.log(main()); // |
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
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}`) // | |
} | |
); |
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
function compare() { | |
return [ | |
'aBcD' === 'abcd', | |
'åbcd' === 'abcd', | |
] | |
} | |
console.log(compare()); // |
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
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