3

I want to run the function myFunction in google app script and the result is a concatenated string.The result i want is 'AB' but my return value is only 'A'.

How should I do it

var data = 'A';

function myFunction() {
    appenData(data);
    Logger.log(data);
}

function appenData(data) {
    data += 'B';
}
2
  • 1
    data is local to appenData (you passed it as parameter) Commented Mar 11, 2020 at 17:42
  • Variable shadowing Commented Mar 11, 2020 at 17:52

1 Answer 1

3

The parameter you passed to appenData(data) is local to the function. If you change your function to:

function appenData() {
    data += 'B';
}

it should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.