Concatenate strings from other functions in javascript

Viewed 77

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';
}
1 Answers

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.

Related