What does the construct x = x || y mean?

It means the title argument is optional. So if you call the method with no arguments it will use a default value of “Error”. It’s shorthand for writing: This kind of shorthand trick with boolean expressions is common in Perl too. With the expression: it evaluates to true if either a or b is true. So if a is true you don’t need to check b at all. This …

Read more

Obtain smallest value from array in Javascript?

The tersest expressive code to find the minimum value is probably rest parameters: Rest parameters are essentially a convenient shorthand for Function.prototype.apply when you don’t need to change the function’s context: This is also a great use case for Array.prototype.reduce: It may be tempting to pass Math.min directly to reduce, however the callback receives additional parameters: In this particular case it may …

Read more