public
Created

Testing to see if an argument has been omitted

  • Download Gist
argtest.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12
function joinArray(arr, separator) {
// if (typeof separator === "undefined") {
// if (separator === undefined) {
// if (arguments.length === 1) {
if (separator == null) {
separator = " - ";
}
return arr.join(separator);
}
joinArray([1, 2, 3]) // "1 - 2 - 3"
joinArray([1, 2, 3], ", ") // "1, 2, 3"
joinArray([1, 2, 3], "") // "123"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.