Edit in JSFiddle

const add = (...nums) => {
  if (nums.length !== 2) {
    throw 'add() requires two arguments'
  }
  return nums[0] + nums[1]
}

if (add(1, 1) === 2) {
  document.write('pass')
} else {
  document.write('fail')
}

try {
  document.write(add(1))
  document.write('fail: no error thrown')
} catch (e) {
  if (e === 'add() requires two arguments') {
    document.write('pass')
  } else {
    document.write('fail: wrong error')
  }
}