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
  • 16,581
  • 13
  • 41
  • 50
Amit Mane
  • 13
  • 1
  • 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
  • 401
  • 5
  • 17
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,615
  • 2
  • 15
  • 31