0

I have a problem receiving a value from a void method

For example:

test() {
    var x = this.test2("hi there");
    console.log(x);
}

test2(data){
    return data;
}

I want to receive the data from test2 but it keep saying undefined what do I do wrong in here? And how can I make this work?

It is probably so basic but I just want to know why I receive the value undefined

Andre Gusmao
  • 224
  • 2
  • 9
Bcoded
  • 83
  • 10

2 Answers2

1

Add function in front of definition.

function test() {
    var x = this.test2("hi there");
    console.log(x);
}

function test2(data) {
    return data;
}

test();
Nitheesh
  • 19,238
  • 3
  • 22
  • 49
0

Try like this :

test(): void {
    var x = this.test2("hi there")
    console.log(x);
}

test2(data): void {
    return data
}
Chandru
  • 10,864
  • 6
  • 38
  • 53