Home » JavaScript » JavaScript Functions » Question
  1. The one-liner code that concatenates all strings passed into a function is

    1. function concatenate()
      {
      return String.concat.apply('', arguments);
      }
    2. function concatenate()
      {
      return String.prototype.concat('', arguments);
      }
    3. function concatenate()
      {
      return String.prototype.concat.apply('', arguments);
      }
    4. function concatenate()
      {
      return String.prototype.apply('', arguments);
      }
    5. None of these
Correct Option: A

The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array. apply takes an array of arguments and treats each element of that array as a single argument.



Your comments will be displayed only after manual approval.