Return a Default Value with Promises Using catch
catch to set a default value instead of a
// Instead of wrapping this block in a try/catch...
const result = await new Promise(
(resolve, reject) => reject("Because Stone Cold said so")
// ...use catch to set the default value (100)
.catch(() => 100);
As a trick I really like what's this brings; as far as readability and maintenance, if you don't know the trick, you might get confused. What do you think?
With Firefox OS, asm.js, and the push for browser performance improvements, canvas and WebGL technologies are opening a world of possibilities. I featured 9 Mind-Blowing Canvas Demos and then took it up a level with 9 Mind-Blowing WebGL Demos, but I want to outdo...
"Copy to clipboard" functionality is something we all use dozens of times daily but the client side API around it has always been lacking; some older APIs and browser implementations required a scary "are you sure?"-style dialog before the content would be copied to clipboard -- not great for...
Chris Coyier authored a post titled Better Pull Quotes: Don't Repeat Markup a while back. In his post he created great-looking pull quotes without repeating any content -- instead he uses jQuery to dynamically create the pull quotes. The following is the...