0

HI I have defined variable called "const VA" but in output it is coming undefine cause of that i am not able to see values inside it below is my code.

function createAddress(streetA, cityA, zipcodeA) {
  return
  {
    streetA, cityA, zipcodeA;
  }
}
const VA = createAddress("405", "newyork", "123456");
console.log(VA);

Output is undefined

FZs
  • 14,438
  • 11
  • 35
  • 45
Amit Mane
  • 13
  • 2

2 Answers2

2

You cannot have a line break for the brackets after the return. Use this instead:

return {
    value,
    value2,
    value3
}
little_monkey
  • 343
  • 3
  • 14
1

Due to automatic semi-colon insertion, if you put a line-break after a return statement, javascript will put a semi-colon after it and nothing will be returned. You simply need to move the curly bracket up onto the same line to prevent this.

Reference: ASI

function createAddress(streetA,cityA,zipcodeA)
      {
          return {
                streetA,
                cityA,
                zipcodeA  
             };
      };


const VA = createAddress ('405','newyork','123456');    
console.log(VA);  
Brian Patterson
  • 1,542
  • 1
  • 13
  • 31